public Fractal(FractalType type, BasisTypes basisType, InterpTypes interpType, int?octaves, double?frequency, uint?seed) { if (octaves == null) { octaves = 8; } if (frequency == null) { frequency = 1.0; } if (seed == null) { seed = 10000; } m_lacunarity = 2.0; SetOctaves((int)octaves); m_frequency = (double)frequency; SetType(type); SetAllSourceTypes(basisType, interpType); SetSeed((uint)seed); }
public override void Draw() { base.Draw(); GUILayout.BeginArea(rect); //Texture if (texture != null) { GUI.DrawTexture(new Rect(0 + rect.width / 8, 0 + rect.height / 5, rect.width - rect.width / 4, rect.height - rect.height / 4), texture); } GUILayout.EndArea(); if (last_end_band != end_band || last_scale_value != scale_value || last_scale_x != scale_x || last_scale_y != scale_y || last_start_band != start_band || last_persistance != persistance || lastType != type || last_seed != seed) { last_scale_x = scale_x; last_scale_y = scale_y; last_scale_value = scale_value; last_start_band = start_band; last_end_band = end_band; last_persistance = persistance; lastType = type; last_seed = seed; Compute(true); } }
public void SetMiratypePlot(string tag) { foreach (LinePlot p in linePlotters) { if (p.SpecificLineType == SpecificLineType.Mira) { fractalPlotter = p; break; } } if (fractalPlotter is LinePlot) { fractalType = fractalPlotter.ThisType; MiraLinePlotter plotter = (MiraLinePlotter)fractalPlotter; string[] favorites = plotter.Favorites; if (favorites.Length > 0) { Int32.TryParse(tag, out int miraType); if (miraType >= 0) { plotter.setFavorite(miraType); if (PlotForm != null) { PlotForm.FormImage = PointsImage.Bitmap; } } } } }
public void Start(FractalType fractalType, DrawingMode drawingMode) { stopWatch.Restart(); this.currentFractalType = fractalType; this.currentDrawingMode = drawingMode; }
public PerformanceLoggerEntry(FractalType fractalType, DrawingMode drawingMode, long totalIterations, int timeTicks) { this.fractalType = fractalType; this.drawingMode = drawingMode; this.totalIterations = totalIterations; this.timeTicks = timeTicks; }
private void CreateNewVisual() { visual = Slot.AddSlot("ComplexFractalVisual"); FractalType fractalType = fractalData.Evaluate(new FractalData(FractalType.none, new double2(0, 0))).fractalType; if (fractalType == FractalType.mandelbrot) { resultTexture = visual.AttachComponent <MandelbrotTexture>(); } else if (fractalType == FractalType.julia) { resultTexture = visual.AttachComponent <JuliaTexture>(); } else if (fractalType == FractalType.newton) { resultTexture = visual.AttachComponent <NewtonTexture>(); } else { return; } ChangeTextureAttributes(); resultMat = visual.AttachComponent <UnlitMaterial>(false, null); resultMat.BlendMode.Value = BlendMode.Transparent; resultMat.Texture.Target = resultTexture; graph = visual.AttachQuad(new float2(0.6f, 0.4f), resultMat, true); AdjustGraphAttributes(); graphRenderer = visual.AttachComponent <MeshRenderer>(); graphRenderer.Materials.Add(); graphRenderer.Materials[0] = resultMat; graphRenderer.Mesh.Target = graph; }
public static double CalculateFor(FractalType type, double length, int iterations) { var initialEdges = DetermineInitialEdgesFor(type); var bumpFactor = DeterminePumpFactorFor(type); var calculator = new SingleFractalCalculator(bumpFactor); double singleResult = calculator.CalculateFor(length, iterations); return singleResult*initialEdges; }
public void PresetPlotter(FractalType type) { if (fractalPlotter != null) { fractalType = type; InitFractal(); } }
public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType) { Octaves = 8; Frequency = 1.00; Lacunarity = 2.00; Type = fractalType; SetAllSourceTypes(basisType, interpolationType); ResetAllSources(); }
public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType, int TerrainOctaves, double TerrainFrequency, int Seed) { this.Octaves = TerrainOctaves; this.Frequency = TerrainFrequency; this.Lacunarity = 2.00; this.Type = fractalType; this.SetAllSourceTypes(basisType, interpolationType); this.ResetAllSources(); }
public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType) { this.Octaves = 8; this.Frequency = 1.00; this.Lacunarity = 2.00; this.Type = fractalType; this.SetAllSourceTypes(basisType, interpolationType); this.ResetAllSources(); }
public ICalculator GenFractalCalc(List<ProcessLayer> LayerData, FractalType fractaltype, string code, ProcessLayer deflayer) { List<ICalculator> c = new List<ICalculator>(); for (int i = 0; i < _processes; i++) { c.Add(_factory.GenFractalCalc(LayerData, fractaltype, code, deflayer)); } return new ThreadCalculator(c.ToArray()); }
private void pictureBoxMiraType(Object sender, EventArgs e) { PictureBox box = (PictureBox)sender; string tag = box.Tag.ToString(); combinedControl.SetMiratypePlot(tag);//setFavoriteLinePlot newType = FractalType.LinePlot; PresetType(); panelExamples.Visible = false; }
public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType, Int32 octaves, double frequency, Int32 seed) { this.seed = seed; this.Octaves = octaves; this.Frequency = frequency; this.Lacunarity = 2.00; this.Type = fractalType; this.SetAllSourceTypes(basisType, interpolationType); this.ResetAllSources(); }
private void selectCurrentLineType(Object sender, EventArgs e) { PictureBox box = (PictureBox)sender; int tag = Int32.Parse(box.Tag.ToString()); combinedControl.Index2LineType(tag); newType = FractalType.LinePlot; PresetType(); panelExamples.Visible = false; }
private Fractal(float rot, int maxIter, Color4 clrRatio, Vector2d pos, double zoom, FractalType fractalType) { this.rot = rot; this.maxIter = maxIter; this.clrRatio = clrRatio; this.pos = pos; this.zoom = zoom; this.fractalType = fractalType; this.crosshair = true; }
public async Task <float[, ]> NoiseMap(int iterations, FractalType type, bool t, params int[] vals) { int len = vals.Length; int yLen = (len < 2 || vals[1] == 0) ? 1 : vals[1]; int xLen = vals[0]; Task[] tasks = new Task[yLen]; var buffer = new float[yLen, xLen]; Setup(len); if (len == 3 && t) { tasks = new Task[yLen / 8]; for (int y = 0, index = 0; y < yLen; y += 8, index++) { int yCopy = y; tasks[index] = Task.Run(() => { Vector <float> yin = new Vector <float>(new float[] { yCopy, yCopy + 1, yCopy + 2, yCopy + 3, yCopy + 4, yCopy + 5, yCopy + 6, yCopy + 7 }); for (int x = 0; x < xLen; ++x) { Vector <float> result = FractalFBM(iterations, new Vector <float>(x), yin, new Vector <float>(vals[2])); buffer[yCopy, x] = result[0]; buffer[yCopy + 1, x] = result[1]; buffer[yCopy + 2, x] = result[2]; buffer[yCopy + 3, x] = result[3]; buffer[yCopy + 4, x] = result[4]; buffer[yCopy + 5, x] = result[5]; buffer[yCopy + 6, x] = result[6]; buffer[yCopy + 7, x] = result[7]; } }); } } else { for (int y = 0; y < yLen; ++y) { int yCopy = y; tasks[y] = Task.Run(() => { for (int x = 0; x < xLen; ++x) { //buffer[yCopy, x] = FractalFBM(iterations, x, yCopy, vals[2]); } }); } } await Task.WhenAll(tasks).ConfigureAwait(false); return(buffer); }
private static int DetermineInitialEdgesFor(FractalType type) { switch (type) { case FractalType.Triangle: return 3; case FractalType.Square: return 4; default: throw new ArgumentOutOfRangeException("type"); } }
public IFractalCalculator Build(FractalType value) { switch (value) { case FractalType.Mandelbrot: return new MandelbrotCalculator(); case FractalType.BurningShip: return new BurningShipCalculator(); default: throw new ArgumentOutOfRangeException(nameof(value)); } }
public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType, int octaves, double frequency, int seed) { this.seed = seed; Octaves = octaves; Frequency = frequency; Octaves = 8; Frequency = 1.00; Lacunarity = 2.00; Type = fractalType; SetAllSourceTypes(basisType, interpolationType); ResetAllSources(); }
public void setVisibility() { newType = combinedControl.fractalPlotter.ThisType; panelParameters.Visible = newType == FractalType.Userdefined; bool juliaMandelPowerType = newType == FractalType.Julia || newType == FractalType.Mandelbrot || newType == FractalType.Multibrot;//newType == FractalType.Lambda || labeljuliaMandelPowerA.Visible = juliaMandelPowerType; textBoxjuliaMandelPowerA.Visible = juliaMandelPowerType; panelJuliaTypes.Visible = juliaMandelPowerType; labelJuliaType.Visible = newType == FractalType.Julia; textBoxJuliaX.Visible = newType == FractalType.Julia; textBoxJuliaY.Visible = newType == FractalType.Julia; panelJuliaTypeGraph.Visible = newType == FractalType.Mandelbrot; panelJuliaTypeGraph.Location = panelParameters.Location; bool linePlotType = newType == FractalType.LinePlot; panelMiraTypes.Visible = linePlotType; if (linePlotType) { panelMiraTypes.Location = new Point(panel1.Width / 2 - panelMiraTypes.Width / 2, buttonSelectType.Top + buttonSelectType.Height + 10);// = panelJuliaTypes.Location; LinePlot plotter = (LinePlot)combinedControl.fractalPlotter; label54.Visible = plotter.UseIterations; hScrollBarIterations.Visible = plotter.UseIterations; labelIterations.Visible = plotter.UseIterations; checkBoxSpreadA.Checked = false; checkBoxSpreadA.Text = plotter.SpreadText; checkBoxSpreadA.Visible = !String.IsNullOrEmpty(plotter.SpreadText); textBoxStartXLineplot.Visible = plotter.UseStartPoint; textBoxStartYLineplot.Visible = plotter.UseStartPoint; labelStartX.Visible = textBoxStartXLineplot.Visible; labelStartY.Visible = textBoxStartYLineplot.Visible; labelScrollB.Visible = plotter.UseBVal; hScrollBarMiraB.Visible = plotter.UseBVal; textBoxBVal.Visible = plotter.UseBVal; panelMiraTypes.BringToFront(); } panelGenerateButtons.Visible = !linePlotType; panelGeneralSettings.Visible = !linePlotType; panelColorPictures.Visible = !linePlotType; createGIFMenuItem.Visible = !linePlotType; }
private void selectCurrentJuliaType(Object sender, EventArgs e) { PictureBox box = (PictureBox)sender; int tag = Int32.Parse(box.Tag.ToString()); combinedControl.Index2JuliaType(tag); newType = FractalType.Julia; PresetType(); panelExamples.Visible = false; textBoxJuliaX.Enabled = tag == juliaTypePictureBoxes.Count - 1; textBoxJuliaY.Enabled = textBoxJuliaX.Enabled; }
public void WriteLogsToService() { String s = ""; for (int a = 0; a < 2; a++) { FractalType fractalType = (FractalType)a; for (int b = 0; b < 3; b++) { DrawingMode drawingMode = (DrawingMode)b; int count = 0; ulong totalIterations = 0; ulong totalTicks = 0; foreach (var entry in entries) { if (entry.drawingMode == drawingMode && entry.fractalType == fractalType) { // pomin pierwszy rekord GPU if (drawingMode == DrawingMode.Gpu && count == 0) { count++; continue; } totalIterations += (ulong)entry.totalIterations; totalTicks += (ulong)entry.timeTicks; count++; } } if (drawingMode == DrawingMode.Gpu) { count--; } if (count > 0) { double performance = (double)totalIterations / totalTicks; s += $"Fraktal: {fractalType}, Tryb: {drawingMode}, Współczynnik wydajności: {performance}#"; } } } if (s != "") { mainWindow.SendMessageToClient(1, s); } }
public FractBox(Int32 fractwidth, Int32 fractheight, FractalType fracType) : base(fractwidth, fractheight) { _fractalType = fracType; InitTransform(fractwidth, fractheight); if (_fractalType == FractalType.Mandelbrot) { ColorMap = this.ColorMapMandelbrot; } else { ColorMap = this.ColorMapJulia; } }
public IFractalCalculator Build(FractalType value) { switch (value) { case FractalType.Mandelbrot: return(new MandelbrotCalculator()); case FractalType.BurningShip: return(new BurningShipCalculator()); default: throw new ArgumentOutOfRangeException(nameof(value)); } }
void DrawFractal(Fractal module) { Rect r = Box(module.editorPos, 9, module); EditorGUI.BeginDisabledGroup(add == module); GUILayout.BeginArea(new Rect(r.x + 16, r.y + 5, r.width - 32, r.height - 10)); EditorGUILayout.LabelField("Fractal", EditorStyles.boldLabel); int seed = EditorGUILayout.DelayedIntField("Seed", module.seed); if (seed != module.seed) { module.seed = seed; } EditorGUILayout.LabelField("Domain Warp"); module.offset = EditorGUILayout.DoubleField("Offset", module.offset); module.scale = EditorGUILayout.DoubleField("Scale", module.scale); FractalType type = (FractalType)EditorGUILayout.EnumPopup("Fractal Type", module.type); if (type != module.type) { module.type = type; } int octaves = EditorGUILayout.DelayedIntField("Octaves", module.octaves); if (octaves != module.octaves) { module.octaves = octaves; } module.frequency = EditorGUILayout.DoubleField("Frequency", module.frequency); module.lacunarity = EditorGUILayout.DoubleField("Lacunarity", module.lacunarity); GUILayout.EndArea(); Vector2 pos = new Vector2(r.x, (int)(r.y + 5 + EditorGUIUtility.singleLineHeight * .5f + (EditorGUIUtility.singleLineHeight + 2f) * 2f + .5f)); // domain warp connection if (module.warpModule != -1) { DrawLine(planet.noiseModules[module.warpModule].editorPos + cameraOffset + new Vector2(moduleWidth * .5f, 0), pos); } ConnectionInputButton( (int nm) => { module.warpModule = nm; }, pos, () => { module.warpModule = -1; }); ConnectionOutputButton(module, new Vector3(r.xMax, r.center.y)); EditorGUI.EndDisabledGroup(); }
private void SetType(FractalType type) { _type = type; switch (type) { case FractalType.FBM: _h = 1.0; _gain = 0; _offset = 0; fB_calcWeights(); break; case FractalType.RIDGEDMULTI: _h = 0.9; _gain = 2; _offset = 1; RidgedMulti_calcWeights(); break; case FractalType.BILLOW: _h = 1; _gain = 0; _offset = 0; Billow_calcWeights(); break; case FractalType.MULTI: _h = 1; _offset = 0; _gain = 0; Multi_calcWeights(); break; case FractalType.HYBRIDMULTI: _h = 0.25; _gain = 1; _offset = 0.7; HybridMulti_calcWeights(); break; default: _h = 1.0; _gain = 0; _offset = 0; fB_calcWeights(); break; } }
public override void DrawInspector() { GUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Scale X"); scale_x = EditorGUILayout.IntField(scale_x); GUILayout.EndVertical(); GUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Scale Y"); scale_y = EditorGUILayout.IntField(scale_y); GUILayout.EndVertical(); GUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Start Band"); start_band = EditorGUILayout.IntField(start_band); GUILayout.EndVertical(); GUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("End Band"); end_band = EditorGUILayout.IntField(end_band); GUILayout.EndVertical(); GUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Scale Value"); scale_value = EditorGUILayout.Slider(scale_value, 0f, 1f); GUILayout.EndVertical(); GUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Persistance"); persistance = EditorGUILayout.Slider(persistance, 0f, 1f); GUILayout.EndVertical(); GUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Fractal Type"); type = (FractalType)EditorGUILayout.EnumPopup(type); GUILayout.EndVertical(); GUILayout.BeginHorizontal("Box"); seed = EditorGUILayout.FloatField(seed); if (GUILayout.Button("Random")) { seed = UnityEngine.Random.Range(0f, 1000000000f); } GUILayout.EndHorizontal(); base.DrawInspector(); }
/// <summary> /// Экземпляр класса FractalAssociationParametrs, который содержить данные о двухмерном фрактале. /// </summary> /// <param name="IterMatrix">Матрица итераций.</param> /// <param name="CreateDate">Дата когда был завершен фрактал.</param> /// <param name="CalculateTime">Время затраченное на вычисления фрактала.</param> /// <param name="IterCount">Количество итераций, при котором строитьс фрактал.</param> /// <param name="LeftEdge">Левая граница, наименьшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая откуда на псевдореальной оси началась постройка фрактала.</param> /// <param name="RightEdge">Правая граница, наибольшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая до куда по оси абцисс строиться фрактал.</param> /// <param name="TopEdge">Верхняя граница, наименьшая координат на псевдореальной оси ординат в декартовой системе координат, укаживающая откуда стоиться фрактал.</param> /// <param name="BottomEdge">Ближайшая граница, наименьшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая откуда строиться фрактал.</param> public FractalAssociationParametrs(ulong[][] IterMatrix, DateTime CreateDate, TimeSpan CalculateTime, ulong IterCount, BigRational LeftEdge, BigRational RightEdge, BigRational TopEdge, BigRational BottomEdge, FractalType FType, object Unique = null) { _fap_create_date = CreateDate; _fap_calculating_time = CalculateTime; _fap_iteration_count = IterCount; _fap_left_edge = LeftEdge; _fap_right_edge = RightEdge; _fap_top_edge = TopEdge; _fap_bottom_edge = BottomEdge; _fap_near_edge = BigRational.Zero; _fap_far_edge = BigRational.Zero; _fap_aplicate_intervals_count = 0; _fap_2d_iterations_matrix = IterMatrix; _fap_3d_segments_matrix = null; _type_of_the_fractal = FType; _unique_parameter = Unique; }
public ICalculator GenFractalCalc(List<ProcessLayer> LayerData, FractalType fractaltype, string code, ProcessLayer deflayer) { BinaryFormatter bin = new BinaryFormatter(); foreach (var client in clients) { var s = client.GetStream(); BinaryWriter bw = new BinaryWriter(s); bw.Write(1); bin.Serialize(s, LayerData); bin.Serialize(s, fractaltype); bin.Serialize(s, code); for (int i = 0; i < LayerData.Count; i++) { if (LayerData[i]==deflayer) bin.Serialize(s, i); } } return new DistributedCalculator(clients); }
private void UpdateVisual() { FractalType fractalType = fractalData.Evaluate(new FractalData(FractalType.none, new double2(0, 0))).fractalType; if ((resultTexture is MandelbrotTexture && fractalType != FractalType.mandelbrot) || (resultTexture is JuliaTexture && fractalType != FractalType.julia) || (resultTexture is NewtonTexture && fractalType != FractalType.newton)) { visual.Destroy(); CreateNewVisual(); } else { ChangeTextureAttributes(); AdjustGraphAttributes(); } }
/// <summary> /// Экземпляр класса для хранения информации и данных о трёхмерном фрактале. /// </summary> /// <param name="_3DFractalAplicateSegmensMatrix">Матрица отрезков фрактала на оси апликат в декартовой системе координат.</param> /// <param name="CreateDate">Дата когда был завершен фрактал.</param> /// <param name="CalculateTime">Врем затраченное на вычисления фрактала.</param> /// <param name="IterCount">Количество итераций, при котором строитьс фрактал.</param> /// <param name="LeftEdge">Левая граница, наименьшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая откуда на псевдореальной оси началась постройка фрактала.</param> /// <param name="RightEdge">Правая граница, наибольшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая до куда по оси абцисс строиться фрактал.</param> /// <param name="TopEdge">Верхняя граница, наименьшая координат на псевдореальной оси ординат в декартовой системе координат, укаживающая откуда стоиться фрактал.</param> /// <param name="BottomEdge">Ближайшая граница, наименьшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая откуда строиться фрактал.</param> /// <param name="NearEdge">Ближайшая граница, наименьшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая откуда строиться фрактал.</param> /// <param name="FarEdge">Дальнейшая граница, наибольшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая до куда строиться фрактал.</param> /// <param name="AplicateIntervalCount">Количество равных интервалов, на которые разбиваем весь доступный отрезок на оси апликат.</param> public FractalAssociationParametrs(int[][][] _3DFractalAplicateSegmensMatrix, DateTime CreateDate, TimeSpan CalculateTime, ulong IterCount, double LeftEdge, double RightEdge, double TopEdge, double BottomEdge, double NearEdge, double FarEdge, int AplicateIntervalCount, FractalType FType, object Unique = null) { _fap_create_date = CreateDate; _fap_calculating_time = CalculateTime; _fap_iteration_count = IterCount; _fap_left_edge = convert_to_br(LeftEdge); _fap_right_edge = convert_to_br(RightEdge); _fap_top_edge = convert_to_br(TopEdge); _fap_bottom_edge = convert_to_br(BottomEdge); _fap_near_edge = convert_to_br(NearEdge); _fap_far_edge = convert_to_br(FarEdge); _fap_aplicate_intervals_count = AplicateIntervalCount; _fap_2d_iterations_matrix = null; _fap_3d_segments_matrix = _3DFractalAplicateSegmensMatrix; _type_of_the_fractal = FType; _unique_parameter = Unique; }
/// <summary> /// Экземпляр класса FractalAssociationParametrs, который содержить данные о двухмерном фрактале. /// </summary> /// <param name="IterMatrix">Матрица итераций.</param> /// <param name="CalculateTime">Врем вычисления фрактала.</param> /// <param name="IterCount">Количество итераций, при котором строитьс фрактал.</param> /// <param name="LeftEdge">Левая граница, наименьшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая откуда на псевдореальной оси началась постройка фрактала.</param> /// <param name="RightEdge">Правая граница, наибольшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая до куда по оси абцисс строиться фрактал.</param> /// <param name="TopEdge">Верхняя граница, наименьшая координат на псевдореальной оси ординат в декартовой системе координат, укаживающая откуда стоиться фрактал.</param> /// <param name="BottomEdge">Ближайшая граница, наименьшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая откуда строиться фрактал.</param> public FractalAssociationParametrs(ulong[][] IterMatrix, TimeSpan CalculateTime, ulong IterCount, double LeftEdge, double RightEdge, double TopEdge, double BottomEdge, FractalType FType, object Unique = null, object Resume = null) { _fap_create_date = DateTime.Now; _fap_calculating_time = CalculateTime; _fap_iteration_count = IterCount; _fap_left_edge = convert_to_br(LeftEdge); _fap_right_edge = convert_to_br(RightEdge); _fap_top_edge = convert_to_br(TopEdge); _fap_bottom_edge = convert_to_br(BottomEdge); _fap_near_edge = BigRational.Zero; _fap_far_edge = BigRational.Zero; _fap_aplicate_intervals_count = 0; _fap_2d_iterations_matrix = IterMatrix; _fap_3d_segments_matrix = null; _type_of_the_fractal = FType; _unique_parameter = Unique; _resume_data = Resume; }
public SimplexNoise(int seed, float frequency) { this.seed = seed; this.frequency = frequency; lacunarity = 0; fractalBounding = 0; fractalType = 0; octaves = 0; gain = 0; fractal = false; GRAD_2D = new GRAD_2D(); X_PRIME = 1619; Y_PRIME = 31337; }
public Fractal(FractalType type, BasisTypes basisType, InterpTypes interpType, int? octaves, double? frequency, uint? seed) { if (octaves == null) octaves = 8; if (frequency == null) frequency = 1.0; if (seed == null) seed = 10000; SetOctaves((int)octaves); m_frequency = (double)frequency; m_lacunarity = 2; SetType(type); SetAllSourceTypes(basisType, interpType); SetSeed((uint)seed); }
private MandelType c_type; // Mandel vagy Julia mod #endregion Fields #region Constructors public Mandel() { c_cent = 0; c_radius = 2; c_saveCent = 0; c_saveRadius = 2; c_type = MandelType.MANDEL_TYPE_MANDEL; c_julia = 0; c_timeused = 0; c_LayerData = new List<ProcessLayer>(); c_fractaltype = FractalType.FRACTAL_TYPE_MANDEL; c_param = 0; c_lineprocess = true; c_processnum = 1; c_function = ""; c_haschanged = true; c_calc = null; c_LayerDataHash = 0; c_factory = null; }
private void SetType(FractalType type) { this.Type = type; switch (type) { case FractalType.FBM: m_H = 1.0; m_gain = 0; m_offset = 0; fBm_calcWeights(); break; case FractalType.RIDGEDMULTI: m_H = 0.9; m_gain = 2; m_offset = 1; RidgedMulti_calcWeights(); break; case FractalType.BILLOW: m_H = 1; m_gain = 0; m_offset = 0; Billow_calcWeights(); break; case FractalType.MULTI: m_H = 1; m_offset = 0; m_gain = 0; Multi_calcWeights(); break; case FractalType.HYBRIDMULTI: m_H = 0.25; m_gain = 1; m_offset = 0.7; HybridMulti_calcWeights(); break; default: m_H = 1.0; m_gain = 0; m_offset = 0; fBm_calcWeights(); break; } ; }
public SimpleCalculator(FractalType fractaltype, string code, ProcessLayer deflayer) { this.fractaltype = fractaltype; if (fractaltype == FractalType.FRACTAL_TYPE_CONVERGENT || fractaltype == FractalType.FRACTAL_TYPE_DIVERGENT) { Microsoft.CSharp.CSharpCodeProvider cp = new Microsoft.CSharp.CSharpCodeProvider(); System.CodeDom.Compiler.CompilerParameters cpar = new System.CodeDom.Compiler.CompilerParameters(); cpar.GenerateInMemory = true; cpar.GenerateExecutable = false; cpar.ReferencedAssemblies.Add("system.dll"); cpar.ReferencedAssemblies.Add(System.Reflection.Assembly.GetExecutingAssembly().Location); cpar.ReferencedAssemblies.Add("system.core.dll"); cpar.ReferencedAssemblies.Add("system.numerics.dll"); string src = "using System;using System.Numerics;using RestFract;using RestFract.Generators;class evalclass:IComplexEval {" + "public evalclass(){} public Complex eval(Complex x, Complex c, double n, double p)" + "{ return " + code + "; } }"; System.CodeDom.Compiler.CompilerResults cr = cp.CompileAssemblyFromSource(cpar, src); if (cr.Errors.Count == 0 && cr.CompiledAssembly != null) { Type ObjType = cr.CompiledAssembly.GetType("evalclass"); try { if (ObjType != null) { this.code = (IComplexEval)Activator.CreateInstance(ObjType); } } catch (Exception e) { this.code = null; throw new NotImplementedException("Could not compile code",e); } } else { this.code = null; throw new NotImplementedException("Could not compile code: "+cr.Errors[0]); } } this.deflayer = deflayer; }
public Fractal(FractalType type, BasisTypes basisType, InterpTypes interpType, int? octaves = null, double? frequency = null, uint? seed = null, double? angle = null, double? lacunarity = null) { if (octaves == null) { octaves = 1; } if (frequency == null) { frequency = 1.0; } if (seed == null) { seed = 10000; } if (angle == null) { angle = 0; } if (lacunarity == null) { lacunarity = 2; } _frequency = frequency.Value; _lacunarity = lacunarity.Value; SetOctaves(octaves.Value); SetType(type); SetAllSourceTypes(basisType, interpType, seed.Value, angle.Value); }
/// <summary> /// Экземпляр класса FractalAssociationParametrs, который содержить данные о двухмерном фрактале. /// </summary> /// <param name="IterMatrix">Матрица итераций.</param> /// <param name="CalculateTime">Врем вычисления фрактала.</param> /// <param name="IterCount">Количество итераций, при котором строитьс фрактал.</param> /// <param name="LeftEdge">Левая граница, наименьшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая откуда на псевдореальной оси началась постройка фрактала.</param> /// <param name="RightEdge">Правая граница, наибольшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая до куда по оси абцисс строиться фрактал.</param> /// <param name="TopEdge">Верхняя граница, наименьшая координат на псевдореальной оси ординат в декартовой системе координат, укаживающая откуда стоиться фрактал.</param> /// <param name="BottomEdge">Ближайшая граница, наименьшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая откуда строиться фрактал.</param> public FractalAssociationParametrs(ulong[][] IterMatrix, TimeSpan CalculateTime, ulong IterCount, double LeftEdge, double RightEdge, double TopEdge, double BottomEdge, FractalType FType, object Unique = null,object Resume=null) { _fap_create_date = DateTime.Now; _fap_calculating_time = CalculateTime; _fap_iteration_count = IterCount; _fap_left_edge = convert_to_br(LeftEdge); _fap_right_edge = convert_to_br(RightEdge); _fap_top_edge = convert_to_br(TopEdge); _fap_bottom_edge = convert_to_br(BottomEdge); _fap_near_edge = BigRational.Zero; _fap_far_edge = BigRational.Zero; _fap_aplicate_intervals_count = 0; _fap_2d_iterations_matrix = IterMatrix; _fap_3d_segments_matrix = null; _type_of_the_fractal = FType; _unique_parameter = Unique; _resume_data = Resume; }
/// <summary> /// Экземпляр класса для хранения информации и данных о трёхмерном фрактале. /// </summary> /// <param name="_3DFractalAplicateSegmensMatrix">Матрица отрезков фрактала на оси апликат в декартовой системе координат.</param> /// <param name="CreateDate">Дата когда был завершен фрактал.</param> /// <param name="CalculateTime">Врем затраченное на вычисления фрактала.</param> /// <param name="IterCount">Количество итераций, при котором строитьс фрактал.</param> /// <param name="LeftEdge">Левая граница, наименьшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая откуда на псевдореальной оси началась постройка фрактала.</param> /// <param name="RightEdge">Правая граница, наибольшая координата на псевдореальной оси абцисс в декартовой системе координат, укаживающая до куда по оси абцисс строиться фрактал.</param> /// <param name="TopEdge">Верхняя граница, наименьшая координат на псевдореальной оси ординат в декартовой системе координат, укаживающая откуда стоиться фрактал.</param> /// <param name="BottomEdge">Ближайшая граница, наименьшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая откуда строиться фрактал.</param> /// <param name="NearEdge">Ближайшая граница, наименьшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая откуда строиться фрактал.</param> /// <param name="FarEdge">Дальнейшая граница, наибольшая координата на псевдореальной оси апликат в декартовой системе координат, укаживающая до куда строиться фрактал.</param> /// <param name="AplicateIntervalCount">Количество равных интервалов, на которые разбиваем весь доступный отрезок на оси апликат.</param> public FractalAssociationParametrs(int[][][] _3DFractalAplicateSegmensMatrix, DateTime CreateDate, TimeSpan CalculateTime, ulong IterCount, BigRational LeftEdge, BigRational RightEdge, BigRational TopEdge, BigRational BottomEdge, BigRational NearEdge, BigRational FarEdge, int AplicateIntervalCount, FractalType FType, object Unique = null) { _fap_create_date = CreateDate; _fap_calculating_time = CalculateTime; _fap_iteration_count = IterCount; _fap_left_edge = LeftEdge; _fap_right_edge = RightEdge; _fap_top_edge = TopEdge; _fap_bottom_edge = BottomEdge; _fap_near_edge = NearEdge; _fap_far_edge = FarEdge; _fap_aplicate_intervals_count = AplicateIntervalCount; _fap_2d_iterations_matrix = null; _fap_3d_segments_matrix = _3DFractalAplicateSegmensMatrix; _type_of_the_fractal = FType; _unique_parameter = Unique; }
private static int DeterminePumpFactorFor(FractalType type) { return DetermineInitialEdgesFor(type) + 1; }
private void SetType(FractalType type) { this.Type = type; switch(type) { case FractalType.FBM: m_H = 1.0; m_gain = 0; m_offset = 0; fBm_calcWeights(); break; case FractalType.RIDGEDMULTI: m_H = 0.9; m_gain = 2; m_offset = 1; RidgedMulti_calcWeights(); break; case FractalType.BILLOW: m_H = 1; m_gain = 0; m_offset = 0; Billow_calcWeights(); break; case FractalType.MULTI: m_H = 1; m_offset = 0; m_gain = 0; Multi_calcWeights(); break; case FractalType.HYBRIDMULTI: m_H = 0.25; m_gain = 1; m_offset = 0.7; HybridMulti_calcWeights(); break; default: m_H=1.0; m_gain=0;m_offset=0; fBm_calcWeights(); break; }; }
public ICalculator GenFractalCalc(List<ProcessLayer> LayerData, FractalType fractaltype, string code, ProcessLayer deflayer) { return new SimpleCalculator(fractaltype, code, deflayer); }
public ICalculator GenFractalCalc(List<ProcessLayer> LayerData, FractalType fractaltype, string code, ProcessLayer deflayer) { bool hastriangle = false; bool fractdiv = true; SeqType modesused = 0; foreach (var it in LayerData) { if (it.c_checktype.HasFlag(SeqCheck.MPL_CHECK_TRIANGLE)) hastriangle = true; if (it.c_checktype.HasFlag(SeqCheck.MPL_CHECK_TRIANGLE_SMOOTH)) hastriangle = true; modesused |= it.c_seqtype; } if (modesused.HasFlag(SeqType.MPL_SEQ_STDDEV)) modesused |= SeqType.MPL_SEQ_VARIANCE; if (modesused.HasFlag(SeqType.MPL_SEQ_VARIANCE)) modesused |= SeqType.MPL_SEQ_VARSX; if (modesused.HasFlag(SeqType.MPL_SEQ_VARSX)) modesused |= SeqType.MPL_SEQ_MEAN; CodeNamespace ns = new CodeNamespace(); CodeTypeDeclaration cl = new CodeTypeDeclaration("FractRunner"); cl.IsClass = true; cl.BaseTypes.Add(typeof(IPreCompiledCalculator)); cl.TypeAttributes = System.Reflection.TypeAttributes.Public; ns.Types.Add(cl); CodeMemberMethod calc = new CodeMemberMethod(); calc.Attributes = MemberAttributes.Public; calc.ReturnType = new CodeTypeReference(typeof(void)); calc.Name = "CalcFractal"; calc.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Complex), "x")); calc.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Complex), "c")); calc.Parameters.Add(new CodeParameterDeclarationExpression(typeof(List<ProcessLayer>), "ld")); calc.Parameters.Add(new CodeParameterDeclarationExpression(typeof(double), "pr")); cl.Members.Add(calc); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "sumx", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "meanx", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "varsx", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "variacex", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "sdx", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "minx", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "maxx", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "deltax", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "deltac", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(double), "delta", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(double), "newxnorm", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(double), "lowbound", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(double), "newd", new CodePrimitiveExpression(0))); if (hastriangle) { if (fractaltype == FractalType.FRACTAL_TYPE_MANDEL) { // trinorm = c.Magnitude; calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(double), "trinorm", new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("c"), "Magnitude") )); } else { // trinorm = c.Norm; calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(double), "trinorm", new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("c"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("c"), "Real")), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("c"), "Imaginary"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("c"), "Imaginary"))) )); } } calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool), "end", new CodePrimitiveExpression(false))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "n", new CodePrimitiveExpression(0))); calc.Statements.Add(new CodeVariableDeclarationStatement(typeof(Complex), "newx", new CodeArgumentReferenceExpression("x"))); // while (!end) CodeIterationStatement itr = new CodeIterationStatement(new CodeSnippetStatement(), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("end"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(false)), new CodeSnippetStatement()); calc.Statements.Add(itr); // n++; itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("n"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("n"), CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1)))); switch (fractaltype) { case FractalType.FRACTAL_TYPE_MANDEL: itr.Statements.Add( new CodeAssignStatement( new CodeVariableReferenceExpression("newx"), new CodeObjectCreateExpression(typeof(Complex), new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Real")), CodeBinaryOperatorType.Subtract, new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Imaginary"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Imaginary"))), CodeBinaryOperatorType.Add, new CodePropertyReferenceExpression(new CodeArgumentReferenceExpression("c"), "Real") ), new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Imaginary")), CodeBinaryOperatorType.Multiply, new CodePrimitiveExpression(2) ), CodeBinaryOperatorType.Add, new CodePropertyReferenceExpression(new CodeArgumentReferenceExpression("c"), "Imaginary") ) ))); //double sx = x.Real; //double sy = x.Imaginary; //return new Complex(sx * sx - sy * sy + c.Real, 2 * sx * sy + c.Imaginary); break; case FractalType.FRACTAL_TYPE_MANDEL_N: itr.Statements.Add(new CodeAssignStatement( new CodeVariableReferenceExpression("newx"), new CodeBinaryOperatorExpression( new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Complex)), "Pow", new CodeArgumentReferenceExpression("x"), new CodeArgumentReferenceExpression("pr") ), CodeBinaryOperatorType.Add, new CodeArgumentReferenceExpression("c") ) )); // return Complex.Pow(x, param) + c; break; case FractalType.FRACTAL_TYPE_BURNINGSHIP: itr.Statements.Add( new CodeAssignStatement( new CodeVariableReferenceExpression("newx"), new CodeObjectCreateExpression(typeof(Complex), new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Real")), CodeBinaryOperatorType.Subtract, new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Imaginary"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Imaginary"))), CodeBinaryOperatorType.Add, new CodePropertyReferenceExpression(new CodeArgumentReferenceExpression("c"), "Real") ), new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression( new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("x"), "Imaginary")) ), CodeBinaryOperatorType.Multiply, new CodePrimitiveExpression(2) ), CodeBinaryOperatorType.Add, new CodePropertyReferenceExpression(new CodeArgumentReferenceExpression("c"), "Imaginary") ) ))); // double sx = x.Real; // double sy = x.Imaginary; // return new Complex(sx * sx - sy * sy + c.Real, 2 * absval(sx * sy) + c.Imaginary); break; case FractalType.FRACTAL_TYPE_BURNINGSHIP_N: itr.Statements.Add(new CodeAssignStatement( new CodeVariableReferenceExpression("newx"), new CodeBinaryOperatorExpression( new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Complex)), "Pow", new CodeObjectCreateExpression(typeof(Complex), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodePropertyReferenceExpression(new CodeArgumentReferenceExpression("x"), "Real")), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodePropertyReferenceExpression(new CodeArgumentReferenceExpression("x"), "Imaginary")) ), new CodeArgumentReferenceExpression("pr") ), CodeBinaryOperatorType.Add, new CodeArgumentReferenceExpression("c") ) )); // return Complex.Pow(new Complex(absval(x.Real), absval(x.Imaginary)), n) + c; break; case FractalType.FRACTAL_TYPE_DIVERGENT: itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newx"), new CodeSnippetExpression(code))); // newx = code.eval(x, c, n, param); break; case FractalType.FRACTAL_TYPE_CONVERGENT: fractdiv = false; itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newx"), new CodeSnippetExpression(code))); break; default: throw new NotSupportedException("Unknown FractalType"); } if (modesused.HasFlag(SeqType.MPL_SEQ_SUM)) { itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("sumx"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("sumx"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("newx")))); //sumx+=newx; } if (modesused.HasFlag(SeqType.MPL_SEQ_MEAN)) { itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("deltac"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newx"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("meanx")))); itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("meanx"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("meanx"), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("deltac"), CodeBinaryOperatorType.Divide, new CodeCastExpression(typeof(double), new CodeVariableReferenceExpression("n")))))); /*Complex delta = newx-meanx; meanx = meanx+delta/(double)n;*/ if (modesused.HasFlag(SeqType.MPL_SEQ_VARSX)) { itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("varsx"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("varsx"), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("deltac"), CodeBinaryOperatorType.Multiply, new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newx"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("meanx")))))); //varsx = varsx + delta*(newx-meanx); if (modesused.HasFlag(SeqType.MPL_SEQ_VARIANCE)) { CodeConditionStatement ifst = new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("n"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(1))); // if (n!=1) { ifst.FalseStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("variacex"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("varsx"), CodeBinaryOperatorType.Divide, new CodeBinaryOperatorExpression(new CodeCastExpression(typeof(double), new CodeVariableReferenceExpression("n")), CodeBinaryOperatorType.Subtract, new CodePrimitiveExpression(1.0))))); //variacex = varsx/((double)n-(double)1); if (modesused.HasFlag(SeqType.MPL_SEQ_STDDEV)) { ifst.FalseStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("sdx"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)), "Sqrt", new CodeVariableReferenceExpression("variacex")))); //sdx = Complex.Sqrt(variacex); } itr.Statements.Add(ifst); } } } if (modesused.HasFlag(SeqType.MPL_SEQ_MIN)) { CodeConditionStatement ifst = new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("n"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(1))); ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("minx"), new CodeVariableReferenceExpression("newx"))); ifst.FalseStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)), "Abs", new CodeVariableReferenceExpression("newx")), CodeBinaryOperatorType.LessThan, new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)), "Abs", new CodeVariableReferenceExpression("minx"))), new CodeAssignStatement(new CodeVariableReferenceExpression("minx"), new CodeVariableReferenceExpression("newx")))); itr.Statements.Add(ifst); //if (n==1) minx=newx; else if (Complex.Abs(newx)<Complex.Abs(minx)) minx=newx; } if (modesused.HasFlag(SeqType.MPL_SEQ_MAX)) { CodeConditionStatement ifst = new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("n"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(1))); ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("maxx"), new CodeVariableReferenceExpression("newx"))); ifst.FalseStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)), "Abs", new CodeVariableReferenceExpression("newx")), CodeBinaryOperatorType.GreaterThan, new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)), "Abs", new CodeVariableReferenceExpression("maxx"))), new CodeAssignStatement(new CodeVariableReferenceExpression("maxx"), new CodeVariableReferenceExpression("newx")))); itr.Statements.Add(ifst); //if (n==1) maxx=newx; else if (Complex.Abs(newx)>Complex.Abs(maxx)) maxx=newx; } if (modesused.HasFlag(SeqType.MPL_SEQ_DELTA)) { itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("deltax"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newx"), CodeBinaryOperatorType.Subtract, new CodeArgumentReferenceExpression("x")))); //deltax = newx-x; } itr.Statements.Add(new CodeVariableDeclarationStatement(typeof(IEnumerator<ProcessLayer>), "pc", new CodeMethodInvokeExpression(new CodeArgumentReferenceExpression("ld"), "GetEnumerator"))); itr.Statements.Add(new CodeVariableDeclarationStatement(typeof(ProcessLayer), "p")); foreach (var p in LayerData) { itr.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("pc"), "MoveNext")); itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("p"), new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("pc"), "Current"))); CodeConditionStatement ifst = new CodeConditionStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_active")); //if (p.c_active) { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_n"), new CodeVariableReferenceExpression("n"))); //p.c_n = n; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_old2x"), new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"))); ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"))); //p.c_old2x = p.c_oldx; //p.c_oldx = p.c_x; switch (p.c_seqtype) { case SeqType.MPL_SEQ_NORMAL: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("newx"))); break; // p.c_x = newx; break; case SeqType.MPL_SEQ_SUM: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("sumx"))); break; // p.c_x = sumx; break; case SeqType.MPL_SEQ_MEAN: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("meanx"))); break; // p.c_x = meanx; break; case SeqType.MPL_SEQ_VARSX: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("varsx"))); break; // p.c_x = variacex; break; case SeqType.MPL_SEQ_VARIANCE: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("variacex"))); break; // p.c_x = variacex; break; case SeqType.MPL_SEQ_STDDEV: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("sdx"))); break; // p.c_x = sdx; break; case SeqType.MPL_SEQ_MIN: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("minx"))); break; // p.c_x = minx; break; case SeqType.MPL_SEQ_MAX: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("maxx"))); break; // p.c_x = maxx; break; case SeqType.MPL_SEQ_DELTA: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("deltax"))); break; // p.c_x = deltax; break; default: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), new CodeVariableReferenceExpression("newx"))); break; // p.c_x = newx; break; } ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePrimitiveExpression(0))); //double newd = 0; switch (p.c_checktype) { case SeqCheck.MPL_CHECK_SMOOTH: if (fractdiv) { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Exp", new CodeBinaryOperatorExpression(new CodePrimitiveExpression(0), CodeBinaryOperatorType.Subtract, new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)), "Abs", new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x")))))); //newd = Math.Exp(-Complex.Abs(p.c_x)); } else { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Exp", new CodeBinaryOperatorExpression(new CodePrimitiveExpression(0), CodeBinaryOperatorType.Subtract, new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)), "Abs", new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), CodeBinaryOperatorType.Subtract, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"))))))); //newd = Math.Exp(-Complex.Abs(p.c_x-p.c_oldx)); } break; case SeqCheck.MPL_CHECK_REAL: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real"))); //newd = p.c_x.Real; break; case SeqCheck.MPL_CHECK_IMAG: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary"))); //newd = p.c_x.Imaginary; break; case SeqCheck.MPL_CHECK_ARG: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Phase"))); //newd = p.c_x.Phase; break; case SeqCheck.MPL_CHECK_ABS: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Magnitude"))); //newd = p.c_x.Magnitude; break; case SeqCheck.MPL_CHECK_CURVATURE: ifst.TrueStatements.Add(new CodeConditionStatement( new CodeBinaryOperatorExpression( new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), CodeBinaryOperatorType.ValueEquality, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_old2x")), new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePrimitiveExpression(0)) }, new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)),"Abs", new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)),"Atan", new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"), CodeBinaryOperatorType.Subtract, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_oldx")), CodeBinaryOperatorType.Divide, new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_oldx"), CodeBinaryOperatorType.Subtract, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_old2x")) ))) ) })); //if ((p.c_oldx!=p.c_old2x)) newd=Complex.Abs(Complex.Atan((p.c_x-p.c_oldx) / (p.c_oldx-p.c_old2x))); else newd=0; } break; case SeqCheck.MPL_CHECK_TRIANGLE: if (fractaltype == FractalType.FRACTAL_TYPE_MANDEL) { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newxnorm"), new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), "Real")), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), "Imaginary"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), "Imaginary"))))); //double newxnorm = p.c_oldx.Norm(); ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("lowbound"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("trinorm"))))); //double lowbound = absval(newxnorm-trinorm); ifst.TrueStatements.Add( new CodeConditionStatement( new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("trinorm")), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(0)), new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePrimitiveExpression(0)) }, new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Magnitude"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")), CodeBinaryOperatorType.Divide, new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("trinorm")), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")))) } )); //if ((newxnorm+trinorm-lowbound)==0) newd=0; else // newd = (p.c_x.Magnitude-lowbound)/(newxnorm+trinorm-lowbound); } else { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newxnorm"), new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Magnitude"))); //double newxnorm = p.c_x.Magnitude; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("lowbound"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("trinorm"))))); //double lowbound = absval(newxnorm-trinorm); ifst.TrueStatements.Add( new CodeConditionStatement( new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("trinorm")), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(0)), new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePrimitiveExpression(0)) }, new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("c")), "Magnitude"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")), CodeBinaryOperatorType.Divide, new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("trinorm")), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")))) } )); //if ((newxnorm+trinorm-lowbound)==0) newd=0; else // newd = ((Complex.Abs(p.c_x-c)-lowbound)/(newxnorm+trinorm-lowbound)); } break; case SeqCheck.MPL_CHECK_TRIANGLE_SMOOTH: if (fractaltype == FractalType.FRACTAL_TYPE_MANDEL) { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newxnorm"), new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), "Real")), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), "Imaginary"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_oldx"), "Imaginary"))))); //double newxnorm = p.c_oldx.Norm(); ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("lowbound"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("trinorm"))))); //double lowbound = absval(newxnorm-trinorm); ifst.TrueStatements.Add( new CodeConditionStatement( new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("trinorm")), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(0)), new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePrimitiveExpression(0)) }, new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Magnitude"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")), CodeBinaryOperatorType.Divide, new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("trinorm")), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")))) } )); //if ((newxnorm+trinorm-lowbound)==0) newd=0; else // newd = (p.c_x.Magnitude-lowbound)/(newxnorm+trinorm-lowbound); } else { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newxnorm"), new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Magnitude"))); //double newxnorm = p.c_x.Magnitude; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("lowbound"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("trinorm"))))); //double lowbound = absval(newxnorm-trinorm); ifst.TrueStatements.Add( new CodeConditionStatement( new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("trinorm")), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(0)), new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodePrimitiveExpression(0)) }, new CodeStatement[] { new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("c")), "Magnitude"), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")), CodeBinaryOperatorType.Divide, new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newxnorm"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("trinorm")), CodeBinaryOperatorType.Subtract, new CodeVariableReferenceExpression("lowbound")))) } )); //if ((newxnorm+trinorm-lowbound)==0) newd=0; else // newd = ((Complex.Abs(p.c_x-c)-lowbound)/(newxnorm+trinorm-lowbound)); } break; case SeqCheck.MPL_CHECK_ORBIT_TRAP: switch (p.c_orbittraptype) { case OrbitTrap.MPL_ORBIT_TRAP_POINT: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)), "Abs", new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), CodeBinaryOperatorType.Subtract, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_pointA"))))); //newd = Complex.Abs(p.c_x - p.c_pointA); break; case OrbitTrap.MPL_ORBIT_TRAP_LINE: if ((p.c_pointA.Real) == 1) { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real")))); //newd = Math.Abs(p.c_x.Real); } else { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Abs", new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary")))); //newd = Math.Abs(p.c_x.Imaginary); } break; case OrbitTrap.MPL_ORBIT_TRAP_GAUSS: { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("newd"), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Complex)),"Abs", new CodeBinaryOperatorExpression(new CodeObjectCreateExpression(typeof(Complex),new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Round", new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real")),new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Round", new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary"))), CodeBinaryOperatorType.Subtract,new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"))))); //Complex gauss = new Complex(Math.Round(p.c_x.Real),Math.Round(p.c_x.Imaginary)); //newd = Complex.Abs(gauss - p.c_x); } break; } break; } switch (p.c_checkseqtype) { case SeqType.MPL_SEQ_NORMAL: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),new CodeVariableReferenceExpression("newd"))); break; case SeqType.MPL_SEQ_SUM: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"), new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"),CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("newd")))); break; // p.c_calc += newd; break; case SeqType.MPL_SEQ_MEAN: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"), new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"), CodeBinaryOperatorType.Add, new CodeVariableReferenceExpression("newd")))); break; // p.c_calc += newd; break; case SeqType.MPL_SEQ_VARSX: { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("delta"),new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newd"), CodeBinaryOperatorType.Subtract, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cmean")))); //double delta = newd - p.c_cmean; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cmean"),new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cmean"),CodeBinaryOperatorType.Add,new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("delta"),CodeBinaryOperatorType.Divide,new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_n"))))); //p.c_cmean = p.c_cmean+delta/p.c_n; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),CodeBinaryOperatorType.Add,new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("delta"),CodeBinaryOperatorType.Multiply,new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newd"),CodeBinaryOperatorType.Subtract,new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cmean")))))); //p.c_calc += delta*(newd-p.c_cmean); } break; case SeqType.MPL_SEQ_VARIANCE: { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("delta"),new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newd"), CodeBinaryOperatorType.Subtract, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cmean")))); //double delta = newd - p.c_cmean; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cmean"),new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cmean"),CodeBinaryOperatorType.Add,new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("delta"),CodeBinaryOperatorType.Divide,new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_n"))))); //p.c_cmean = p.c_cmean+delta/p.c_n; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cvarsx"),new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cvarsx"),CodeBinaryOperatorType.Add,new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("delta"),CodeBinaryOperatorType.Multiply,new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newd"),CodeBinaryOperatorType.Subtract,new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cmean")))))); //p.c_cvarsx = p.c_cvarsx + delta*(newd-p.c_cmean); ifst.TrueStatements.Add(new CodeConditionStatement( new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_n"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(1)), new CodeStatement[] { }, new CodeStatement[] { new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cvarsx"),CodeBinaryOperatorType.Divide,new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_n"),CodeBinaryOperatorType.Subtract,new CodePrimitiveExpression(1.0)))) })); /*if (p.c_n!=1) { p.c_calc = p.c_cvarsx/(p.c_n-1.0); }*/ } break; case SeqType.MPL_SEQ_STDDEV: { ifst.TrueStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("delta"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newd"), CodeBinaryOperatorType.Subtract, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cmean")))); //double delta = newd - p.c_cmean; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cmean"), new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cmean"), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("delta"), CodeBinaryOperatorType.Divide, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_n"))))); //p.c_cmean = p.c_cmean+delta/p.c_n; ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cvarsx"), new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cvarsx"), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("delta"), CodeBinaryOperatorType.Multiply, new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newd"), CodeBinaryOperatorType.Subtract, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cmean")))))); //p.c_cvarsx = p.c_cvarsx + delta*(newd-p.c_cmean); ifst.TrueStatements.Add(new CodeConditionStatement( new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_n"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(1)), new CodeStatement[] { }, new CodeStatement[] { new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cvariance"),new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_cvarsx"),CodeBinaryOperatorType.Divide,new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_n"),CodeBinaryOperatorType.Subtract,new CodePrimitiveExpression(1.0)))) })); /*if (p.c_n!=1) { p.c_cvariance = p.c_cvarsx/(p.c_n-1.0); }*/ ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"),new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)), "Sqrt",new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_cvariance")))); //p.c_calc = Math.Sqrt(p.c_cvariance); } break; case SeqType.MPL_SEQ_MIN: ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_n"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(1)), new CodeStatement[] { new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"), new CodeVariableReferenceExpression("newd")) }, new CodeStatement[] { new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),CodeBinaryOperatorType.GreaterThan,new CodeVariableReferenceExpression("newd")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),new CodeVariableReferenceExpression("newd")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_resx"),new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_resn"),new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_n"))) })); //if (p.c_n==1) p.c_calc=newd; else if (p.c_calc>newd) { p.c_calc = newd; p.c_resx = p.c_x; p.c_resn = p.c_n; } break; case SeqType.MPL_SEQ_MAX: ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_n"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(1)), new CodeStatement[] { new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"), new CodeVariableReferenceExpression("newd")) }, new CodeStatement[] { new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),CodeBinaryOperatorType.LessThan,new CodeVariableReferenceExpression("newd")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),new CodeVariableReferenceExpression("newd")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_resx"),new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_resn"),new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_n"))) })); // if (p.c_n==1) p.c_calc=newd; else if (p.c_calc<newd) { p.c_calc = newd; p.c_resx = p.c_x; p.c_resn = p.c_n; } break; case SeqType.MPL_SEQ_DELTA: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"),new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("newd"), CodeBinaryOperatorType.Subtract,new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc")))); //p.c_calc = newd-p.c_calc; break; default: ifst.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_calc"), new CodeVariableReferenceExpression("newd"))); //p.c_calc = newd; break; } if (p.c_convchktype==ConvCheck.MPL_CONVCHK_REAL) { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Real"),CodeBinaryOperatorType.Multiply,new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Real")),fractdiv ? CodeBinaryOperatorType.GreaterThan : CodeBinaryOperatorType.LessThan,new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_bailout")),new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_active"),new CodePrimitiveExpression(false)))); /*double ddd = p.c_x.Real*p.c_x.Real; if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false;*/ } else if (p.c_convchktype==ConvCheck.MPL_CONVCHK_IMAG) { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary")), fractdiv ? CodeBinaryOperatorType.GreaterThan : CodeBinaryOperatorType.LessThan, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_bailout")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_active"), new CodePrimitiveExpression(false)))); /*double ddd = p.c_x.Imaginary*p.c_x.Imaginary; if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false;*/ } else if (p.c_convchktype==ConvCheck.MPL_CONVCHK_OR) { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary"), CodeBinaryOperatorType.Multiply,new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary")),CodeBinaryOperatorType.BooleanOr,new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real"))), fractdiv ? CodeBinaryOperatorType.GreaterThan : CodeBinaryOperatorType.LessThan, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_bailout")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_active"), new CodePrimitiveExpression(false)))); /*if ((fractdiv) && ((p.c_x.Real*p.c_x.Real>p.c_bailout) || (p.c_x.Imaginary*p.c_x.Imaginary>p.c_bailout))) p.c_active = false; if (!(fractdiv) && ((p.c_x.Real*p.c_x.Real<p.c_bailout) || (p.c_x.Imaginary*p.c_x.Imaginary<p.c_bailout))) p.c_active = false;*/ } else if (p.c_convchktype==ConvCheck.MPL_CONVCHK_AND) { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary")), CodeBinaryOperatorType.BooleanAnd, new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real"))), fractdiv ? CodeBinaryOperatorType.GreaterThan : CodeBinaryOperatorType.LessThan, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_bailout")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_active"), new CodePrimitiveExpression(false)))); /*if ((fractdiv) && ((p.c_x.Real*p.c_x.Real>p.c_bailout) && (p.c_x.Imaginary*p.c_x.Imaginary>p.c_bailout))) p.c_active = false; if (!(fractdiv) && ((p.c_x.Real*p.c_x.Real<p.c_bailout) && (p.c_x.Imaginary*p.c_x.Imaginary<p.c_bailout))) p.c_active = false;*/ } else if (p.c_convchktype==ConvCheck.MPL_CONVCHK_MANH) { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)),"Abs",new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Imaginary")),CodeBinaryOperatorType.Add,new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)),"Abs",new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Real"))),CodeBinaryOperatorType.Multiply,new CodeBinaryOperatorExpression(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)),"Abs",new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Imaginary")),CodeBinaryOperatorType.Add,new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Math)),"Abs",new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Real")))),fractdiv ? CodeBinaryOperatorType.GreaterThan : CodeBinaryOperatorType.LessThan, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_bailout")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_active"), new CodePrimitiveExpression(false)))); /*double ddd = (absval(p.c_x.Imaginary)+absval(p.c_x.Real))*(absval(p.c_x.Imaginary)+absval(p.c_x.Real)); if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false;*/ } else if (p.c_convchktype==ConvCheck.MPL_CONVCHK_MANR) { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Real"),CodeBinaryOperatorType.Add,new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Imaginary")),CodeBinaryOperatorType.Multiply,new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Real"),CodeBinaryOperatorType.Add,new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_x"),"Imaginary"))),fractdiv ? CodeBinaryOperatorType.GreaterThan : CodeBinaryOperatorType.LessThan, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_bailout")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_active"), new CodePrimitiveExpression(false)))); /*double ddd = (p.c_x.Real+p.c_x.Imaginary)*(p.c_x.Real+p.c_x.Imaginary); if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false; */ } else { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Real")), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary"), CodeBinaryOperatorType.Multiply, new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_x"), "Imaginary"))), fractdiv ? CodeBinaryOperatorType.GreaterThan : CodeBinaryOperatorType.LessThan, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_bailout")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_active"), new CodePrimitiveExpression(false)))); /*double ddd = p.c_x.Norm(); if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false;*/ } ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression( new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_n"),CodeBinaryOperatorType.GreaterThan,new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_nlimit")), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_active"),new CodePrimitiveExpression(false)), new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_isin"),new CodePrimitiveExpression(true)) )); //if (p.c_n>p.c_nlimit) { p.c_active = false; p.c_isin = true; } if (p.c_checktype == SeqCheck.MPL_CHECK_TRIANGLE_SMOOTH) { throw new NotImplementedException("Smooth triangle algorithm is unavailable in this CalculatorFactory"); /*if (p.c_active == false) if (!p.c_isin) { p.c_oldx = p.c_x; p.c_x = Fractal_Mandel(p.c_x,c); p.c_n++; double newxnorm = p.c_oldx.Norm(); double lowbound = absval(newxnorm-trinorm); if ((newxnorm+trinorm-lowbound)==0) newd=0; else newd = (p.c_x.Magnitude-lowbound)/(newxnorm+trinorm-lowbound); p.c_calc += newd; double oldsum = p.c_calc/(p.c_n+1); double il2=1/Math.Log(2); double lp=Math.Log(Math.Log(p.c_bailout)); double f=il2*lp-il2*Math.Log(Math.Log(Complex.Abs(p.c_x)))+2; double az2 = p.c_x.Norm(); p.c_oldx = p.c_x; p.c_x = Fractal_Mandel(p.c_oldx,c); lowbound = absval(az2-trinorm); if ((az2+trinorm-lowbound)!=0) p.c_calc+=(Complex.Abs(p.c_x)-lowbound)/(az2+trinorm-lowbound); p.c_n++; p.c_calc = p.c_calc/(p.c_n+1); p.c_calc = oldsum+(p.c_calc-oldsum)*(f-1); } else { p.c_calc /= p.c_n+1; }*/ } else if (p.c_checkseqtype == SeqType.MPL_SEQ_MEAN) { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_active"),CodeBinaryOperatorType.ValueEquality,new CodePrimitiveExpression(false)),new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_calc"),CodeBinaryOperatorType.Divide,new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"),"c_n"),CodeBinaryOperatorType.Add,new CodePrimitiveExpression(1)))))); //if (p.c_active == false) p.c_calc /= p.c_n+1; } if (p == deflayer) { ifst.TrueStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("p"), "c_active"), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(false)),new CodeAssignStatement(new CodeVariableReferenceExpression("end"), new CodePrimitiveExpression(true)))); /*if (!deflayer.c_active) end = true; */ } itr.Statements.Add(ifst); } itr.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("x"), new CodeVariableReferenceExpression("newx"))); // x = newx; CodeCompileUnit compileUnit = new CodeCompileUnit(); compileUnit.Namespaces.Add(ns); compileUnit.ReferencedAssemblies.Add(typeof(ICalculator).Assembly.Location); compileUnit.ReferencedAssemblies.Add(typeof(Complex).Assembly.Location); #if USE_CPP Microsoft.VisualC.CppCodeProvider10 cs = new Microsoft.VisualC.CppCodeProvider10(); //CSharpCodeProvider cs = new CSharpCodeProvider(new Dictionary<string, string>(){ {"CompilerVersion", "v4.0"} }); CompilerParameters opts = new CompilerParameters(); opts.GenerateExecutable = false; opts.GenerateInMemory = true; opts.IncludeDebugInformation = false; using (Stream s = File.Open("test.cpp",FileMode.Create)) using (StreamWriter sw = new StreamWriter(s)) cs.GenerateCodeFromCompileUnit(compileUnit,sw,new CodeGeneratorOptions()); var pr = System.Diagnostics.Process.Start(@"cmd", @"/c """"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"" & ""c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe"""" test.cpp /CLR:PURE /O2 /LD /GS-"); pr.WaitForExit(); Assembly assembly = Assembly.Load(File.ReadAllBytes("test.dll"), null); #else CSharpCodeProvider cs = new CSharpCodeProvider(new Dictionary<string, string>(){ {"CompilerVersion", "v4.0"} }); CompilerParameters opts = new CompilerParameters(); opts.GenerateExecutable = false; opts.GenerateInMemory = true; opts.IncludeDebugInformation = false; CompilerResults res = cs.CompileAssemblyFromDom(opts, compileUnit); /*using (Stream s = File.Open("test.cs", FileMode.Create)) using (StreamWriter sw = new StreamWriter(s)) cs.GenerateCodeFromCompileUnit(compileUnit, sw, new CodeGeneratorOptions());*/ foreach (CompilerError error in res.Errors) { if (!error.IsWarning) { throw new NotImplementedException(error.ErrorText + " " + error.Line.ToString()); } } Assembly assembly = res.CompiledAssembly; #endif return new PreCompiledCalculator((IPreCompiledCalculator)Activator.CreateInstance(assembly.GetType("FractRunner"))); }
public ICalculator GenFractalCalc(List<ProcessLayer> LayerData, FractalType fractaltype, string code, ProcessLayer deflayer) { string macros = @" #pragma OPENCL EXTENSION cl_amd_printf : enable inline float ABS(float a) { return a>0?a:-a; } inline float ARGC(float2 a) { return atan2(a.y,a.x); } inline float NORM(float2 a) { return a.x*a.x+a.y*a.y; } inline float ABSC(float2 a) { return sqrt(NORM(a)); } inline float2 MULC(float2 a, float2 b) { return (float2)( a.x*b.x-a.y*b.y, a.y*b.x+a.x*b.y ); } inline float2 DIVC(float2 a, float2 b) { return (float2)( (a.x*b.x+a.y*b.y)/(b.x*b.x+b.y*b.y), (a.y*b.x-a.x*b.y)/(b.x*b.x+b.y*b.y) ); } inline float2 lnc(float2 c) { float r = ABSC(c); float a = ARGC(c); return (float2)(log(r),a); } inline float2 arctanc(float2 c) { float2 io = (float2)(0.0f,1.0f); float2 two = (float2)(2.0f,0.0f); float2 one = (float2)(1.0f,0.0f); return (float2)(MULC(DIVC(io,two),lnc(one - MULC(io,c))-lnc(one + MULC(io,c)))); } inline float2 powc(float2 c, float p) { if (NORM(c)==0) { return (float2)(0.0f,0.0f); } else { float r = pow(ABSC(c),p); float a = ARGC(c)*p; return (float2)(r*cos(a),r*sin(a)); } } struct ProcessLayer { float2 c_old2x; float2 c_oldx; float2 c_x; float2 c_resx; float c_calc; float c_cmean; float c_cvarsx; float c_cvariance; int c_active; int c_isin; int c_n; int c_resn; }; kernel void FractalCalc ( global read_only float2* in_x, global read_only float2* in_c, "; StringBuilder kernel = new StringBuilder(macros); for (int i=0; i< LayerData.Count; i++) { kernel.Append(" global write_only struct ProcessLayer* out_p" + i); kernel.Append(i+1==LayerData.Count ? "\n){" : ",\n"); } bool hastriangle = false; bool fractdiv = true; SeqType modesused = 0; foreach (var it in LayerData) { if (it.c_checktype.HasFlag(SeqCheck.MPL_CHECK_TRIANGLE)) hastriangle = true; if (it.c_checktype.HasFlag(SeqCheck.MPL_CHECK_TRIANGLE_SMOOTH)) hastriangle = true; modesused |= it.c_seqtype; } if (modesused.HasFlag(SeqType.MPL_SEQ_STDDEV)) modesused |= SeqType.MPL_SEQ_VARIANCE; if (modesused.HasFlag(SeqType.MPL_SEQ_VARIANCE)) modesused |= SeqType.MPL_SEQ_VARSX; if (modesused.HasFlag(SeqType.MPL_SEQ_VARSX)) modesused |= SeqType.MPL_SEQ_MEAN; kernel.Append("float2 sumx = (float2)(0.0f,0.0f);"); kernel.Append("float2 meanx = (float2)(0.0f,0.0f);"); kernel.Append("float2 varsx = (float2)(0.0f,0.0f);"); kernel.Append("float2 variacex = (float2)(0.0f,0.0f);"); kernel.Append("float2 sdx = (float2)(0.0f,0.0f);"); kernel.Append("float2 minx = (float2)(0.0f,0.0f);"); kernel.Append("float2 maxx = (float2)(0.0f,0.0f);"); kernel.Append("float2 deltax = (float2)(0.0f,0.0f);"); kernel.Append("float2 deltac = (float2)(0.0f,0.0f);"); kernel.Append("float delta = 0.0f;"); kernel.Append("float newxnorm = 0.0f;"); kernel.Append("float lowbound = 0.0f;"); kernel.Append("float newd = 0.0f;"); kernel.Append("int end = 0;"); kernel.Append("int n = 0;"); kernel.Append("float2 newx = (float2)(0.0f,0.0f);"); kernel.Append("int index = get_global_id(0);"); kernel.Append("float2 x = in_x[index];"); kernel.Append("float2 c = in_c[index];"); for (int i = 0; i < LayerData.Count; i++) { kernel.Append("struct ProcessLayer p"+i+";"); kernel.Append("p"+i+".c_active = 1;"); kernel.Append("p"+i+".c_isin = 0;"); kernel.Append("p"+i+".c_x = x;"); kernel.Append("p"+i+".c_oldx = x;"); kernel.Append("p"+i+".c_old2x = x;"); kernel.Append("p"+i+".c_calc = 0;"); kernel.Append("p"+i+".c_cmean = 0;"); kernel.Append("p"+i+".c_cvarsx = 0;"); kernel.Append("p"+i+".c_cvariance = 0;"); } kernel.Append("struct ProcessLayer* p = 0;"); if (hastriangle) { if (fractaltype == FractalType.FRACTAL_TYPE_MANDEL) { kernel.Append("float trinorm = ABSC(c);"); // trinorm = c.Magnitude; } else { kernel.Append("float trinorm = NORM(c);"); // trinorm = c.Norm; } } kernel.Append("while (!end) {"); // while (!end) kernel.Append("n++;"); // n++; switch (fractaltype) { case FractalType.FRACTAL_TYPE_MANDEL: kernel.Append("newx = (float2)(x.x*x.x - x.y*x.y,2*x.x*x.y) + c;"); //kernel.Append(@"printf(""%f %f - "",newx.x,newx.y);"); //double sx = x.Real; //double sy = x.Imaginary; //return new Complex(sx * sx - sy * sy + c.Real, 2 * sx * sy + c.Imaginary); break; case FractalType.FRACTAL_TYPE_MANDEL_N: kernel.Append("newx = powc(x,pr) + c;"); // return Complex.Pow(x, param) + c; break; case FractalType.FRACTAL_TYPE_BURNINGSHIP: kernel.Append("newx = (float2)(x.x*x.x-x.y*x.y,2*ABS(x.x*x.y)) + c;"); // double sx = x.Real; // double sy = x.Imaginary; // return new Complex(sx * sx - sy * sy + c.Real, 2 * absval(sx * sy) + c.Imaginary); break; case FractalType.FRACTAL_TYPE_BURNINGSHIP_N: kernel.Append("newx = powc((ABS(x.x),ABS(x.y)),pr) + c;"); // return Complex.Pow(new Complex(absval(x.Real), absval(x.Imaginary)), n) + c; break; case FractalType.FRACTAL_TYPE_DIVERGENT: kernel.Append("newx = " + code + ";"); // newx = code.eval(x, c, n, param); break; case FractalType.FRACTAL_TYPE_CONVERGENT: kernel.Append("newx = " + code + ";"); fractdiv = false; break; default: throw new NotSupportedException("Unknown FractalType"); } if (modesused.HasFlag(SeqType.MPL_SEQ_SUM)) { kernel.Append("sumx += newx;"); //sumx+=newx; } if (modesused.HasFlag(SeqType.MPL_SEQ_MEAN)) { kernel.Append("deltax = newx-meanx;"); kernel.Append("meanx += deltax/(float)n;"); /*Complex delta = newx-meanx; meanx = meanx+delta/(double)n;*/ if (modesused.HasFlag(SeqType.MPL_SEQ_VARSX)) { kernel.Append("varsx += MULC(deltax,(newx-meanx));"); //varsx = varsx + delta*(newx-meanx); if (modesused.HasFlag(SeqType.MPL_SEQ_VARIANCE)) { kernel.Append("if (n!=1) {"); // if (n!=1) { kernel.Append("variacex = varsx / (float)((float)n-(float)1.0f);"); //variacex = varsx/((double)n-(double)1); if (modesused.HasFlag(SeqType.MPL_SEQ_STDDEV)) { kernel.Append("sdx = powc(variacex,0.5f);"); //sdx = Complex.Sqrt(variacex); } kernel.Append("}"); } } } if (modesused.HasFlag(SeqType.MPL_SEQ_MIN)) { kernel.Append("if (n==1) minx = newx; else {"); kernel.Append("if (NORM(newx)<NORM(minx)) { minx = newx; } }"); //if (n==1) minx=newx; else if (Complex.Abs(newx)<Complex.Abs(minx)) minx=newx; } if (modesused.HasFlag(SeqType.MPL_SEQ_MAX)) { kernel.Append("if (n==1) maxx = newx; else {"); kernel.Append("if (NORM(newx)>NORM(maxx)) { maxx = newx; } }"); //if (n==1) maxx=newx; else if (Complex.Abs(newx)>Complex.Abs(maxx)) maxx=newx; } if (modesused.HasFlag(SeqType.MPL_SEQ_DELTA)) { kernel.Append("deltax = newx - x"); //deltax = newx-x; } for (int i=0; i< LayerData.Count; i++) { var p = LayerData[i]; kernel.Append("p = &p"+i+";"); kernel.Append("if (p->c_active) {"); //if (p.c_active) { kernel.Append("p->c_n = n;"); //p.c_n = n; kernel.Append("p->c_old2x = p->c_oldx;"); kernel.Append("p->c_oldx = p->c_x;"); //p.c_old2x = p.c_oldx; //p.c_oldx = p.c_x; switch (p.c_seqtype) { case SeqType.MPL_SEQ_NORMAL: kernel.Append("p->c_x = newx;"); break; // p.c_x = newx; break; case SeqType.MPL_SEQ_SUM: kernel.Append("p->c_x = sumx;"); break; // p.c_x = sumx; break; case SeqType.MPL_SEQ_MEAN: kernel.Append("p->c_x = meanx;"); break;// p.c_x = meanx; break; case SeqType.MPL_SEQ_VARSX: kernel.Append("p->c_x = varsx;"); break; case SeqType.MPL_SEQ_VARIANCE: kernel.Append("p->c_x = variacex;"); break; // p.c_x = variacex; break; case SeqType.MPL_SEQ_STDDEV: kernel.Append("p->c_x = sdx;"); break; // p.c_x = sdx; break; case SeqType.MPL_SEQ_MIN: kernel.Append("p->c_x = minx;"); break; // p.c_x = minx; break; case SeqType.MPL_SEQ_MAX: kernel.Append("p->c_x = maxx;"); break; // p.c_x = maxx; break; case SeqType.MPL_SEQ_DELTA: kernel.Append("p->c_x = deltax;"); break; // p.c_x = deltax; break; default: kernel.Append("p->c_x = newx;"); break; // p.c_x = newx; break; } kernel.Append("newd = 0;"); //double newd = 0; switch (p.c_checktype) { case SeqCheck.MPL_CHECK_SMOOTH: if (fractdiv) { kernel.Append("newd = exp(-ABSC(p->c_x));"); //newd = Math.Exp(-Complex.Abs(p.c_x)); } else { kernel.Append("newd = exp(-ABSC(p->c_x-p->c_oldx));"); //newd = Math.Exp(-Complex.Abs(p.c_x-p.c_oldx)); } break; case SeqCheck.MPL_CHECK_REAL: kernel.Append("newd = p->c_x.x;"); //newd = p.c_x.Real; break; case SeqCheck.MPL_CHECK_IMAG: kernel.Append("newd = p->c_x.y;"); //newd = p.c_x.Imaginary; break; case SeqCheck.MPL_CHECK_ARG: kernel.Append("newd = atan2(p->c_x.y,p->c_x.x);"); //newd = p.c_x.Phase; break; case SeqCheck.MPL_CHECK_ABS: kernel.Append("newd = ABSC(p->c_x);"); //newd = p.c_x.Magnitude; break; case SeqCheck.MPL_CHECK_CURVATURE: kernel.Append("if (isnotequal(p.c_oldx,p.c_old2x)) { newd = ABSC(atanc(DIVC(p->c_x-p->c_oldx,p->c_oldx-p->c_old2x))); } else newd = 0;"); //if ((p.c_oldx!=p.c_old2x)) newd=Complex.Abs(Complex.Atan((p.c_x-p.c_oldx) / (p.c_oldx-p.c_old2x))); else newd=0; } break; case SeqCheck.MPL_CHECK_TRIANGLE: if (fractaltype == FractalType.FRACTAL_TYPE_MANDEL) { kernel.Append("newxnorm = NORM(p->c_oldx);"); //double newxnorm = p.c_oldx.Norm(); kernel.Append("lowbound = ABS(newxnorm-trinorm);"); //double lowbound = absval(newxnorm-trinorm); kernel.Append("if ((newxnorm+trinorm-lowbound)==0) newd = 0; else newd = (ABSC(p->c_x)-lowbound)/(newxnorm+trinorm-lowbound);"); //if ((newxnorm+trinorm-lowbound)==0) newd=0; else // newd = (p.c_x.Magnitude-lowbound)/(newxnorm+trinorm-lowbound); } else { kernel.Append("newxnorm = ABSC(p->c_x);"); //double newxnorm = p.c_x.Magnitude; kernel.Append("lowbound = ABS(newxnorm-trinorm);"); //double lowbound = absval(newxnorm-trinorm); kernel.Append("if ((newxnorm+trinorm-lowbound)==0) newd = 0; else newd = (ABSC(p->c_x-c)-lowbound)/(newxnorm+trinorm-lowbound);"); //if ((newxnorm+trinorm-lowbound)==0) newd=0; else // newd = ((Complex.Abs(p.c_x-c)-lowbound)/(newxnorm+trinorm-lowbound)); } break; case SeqCheck.MPL_CHECK_TRIANGLE_SMOOTH: if (fractaltype == FractalType.FRACTAL_TYPE_MANDEL) { kernel.Append("newxnorm = NORM(p->c_oldx);"); //double newxnorm = p.c_oldx.Norm(); kernel.Append("lowbound = ABS(newxnorm-trinorm);"); //double lowbound = absval(newxnorm-trinorm); kernel.Append("if ((newxnorm+trinorm-lowbound)==0) newd = 0; else newd = (ABSC(p->c_x)-lowbound)/(newxnorm+trinorm-lowbound);"); //if ((newxnorm+trinorm-lowbound)==0) newd=0; else // newd = (p.c_x.Magnitude-lowbound)/(newxnorm+trinorm-lowbound); } else { kernel.Append("newxnorm = ABSC(p->c_x);"); //double newxnorm = p.c_x.Magnitude; kernel.Append("lowbound = ABS(newxnorm-trinorm);"); //double lowbound = absval(newxnorm-trinorm); kernel.Append("if ((newxnorm+trinorm-lowbound)==0) newd = 0; else newd = (ABSC(p->c_x-c)-lowbound)/(newxnorm+trinorm-lowbound);"); //if ((newxnorm+trinorm-lowbound)==0) newd=0; else // newd = ((Complex.Abs(p.c_x-c)-lowbound)/(newxnorm+trinorm-lowbound)); } break; case SeqCheck.MPL_CHECK_ORBIT_TRAP: switch (p.c_orbittraptype) { case OrbitTrap.MPL_ORBIT_TRAP_POINT: kernel.Append("newd = ABSC(p->c_x - p->c_pointA);"); //newd = Complex.Abs(p.c_x - p.c_pointA); break; case OrbitTrap.MPL_ORBIT_TRAP_LINE: if ((p.c_pointA.Real) == 1) { kernel.Append("newd = ABS(p->c_x.x);"); //newd = Math.Abs(p.c_x.Real); } else { kernel.Append("newd = ABS(p->c_x.y);"); //newd = Math.Abs(p.c_x.Imaginary); } break; case OrbitTrap.MPL_ORBIT_TRAP_GAUSS: { kernel.Append("newd = ABSC((round(p->c_x.x),round(p->c_x.y)) - p->c_x);"); //Complex gauss = new Complex(Math.Round(p.c_x.Real),Math.Round(p.c_x.Imaginary)); //newd = Complex.Abs(gauss - p.c_x); } break; } break; } switch (p.c_checkseqtype) { case SeqType.MPL_SEQ_NORMAL: kernel.Append("p->c_calc = newd;"); break; case SeqType.MPL_SEQ_SUM: kernel.Append("p->c_calc += newd;"); break; // p.c_calc += newd; break; case SeqType.MPL_SEQ_MEAN: kernel.Append("p->c_calc += newd;"); break; // p.c_calc += newd; break; case SeqType.MPL_SEQ_VARSX: { kernel.Append("delta = newd - p->c_cmean;"); //double delta = newd - p.c_cmean; kernel.Append("p->c_cmean = p->c_cmean + delta / p->c_n;"); //p.c_cmean = p.c_cmean+delta/p.c_n; kernel.Append("p->c_calc += delta * (newd - p->c_cmean);"); //p.c_calc += delta*(newd-p.c_cmean); } break; case SeqType.MPL_SEQ_VARIANCE: { kernel.Append("delta = newd - p->c_cmean;"); //double delta = newd - p.c_cmean; kernel.Append("p->c_cmean = p->c_cmean + delta / p->c_n;"); //p.c_cmean = p.c_cmean+delta/p.c_n; kernel.Append("p->c_cvarsx += delta * (newd - p->c_cmean);"); //p.c_cvarsx = p.c_cvarsx + delta*(newd-p.c_cmean); kernel.Append("if (p->c_n!=1) { p->c_calc = p->c_cvarsx/(p->c_n-1.0f); }"); /*if (p.c_n!=1) { p.c_calc = p.c_cvarsx/(p.c_n-1.0); }*/ } break; case SeqType.MPL_SEQ_STDDEV: { kernel.Append("delta = newd - p->c_cmean;"); //double delta = newd - p.c_cmean; kernel.Append("p->c_cmean = p->c_cmean + delta / p->c_n;"); //p.c_cmean = p.c_cmean+delta/p.c_n; kernel.Append("p->c_cvarsx += delta * (newd - p->c_cmean);"); //p.c_cvarsx = p.c_cvarsx + delta*(newd-p.c_cmean); kernel.Append("if (p->c_n!=1) { p->c_cvariance = p->c_cvarsx/((float)p->c_n-1.0f);"); /*if (p.c_n!=1) { p.c_cvariance = p.c_cvarsx/(p.c_n-1.0); }*/ kernel.Append("p->c_calc = sqrt(p->c_cvariance);"); //p.c_calc = Math.Sqrt(p.c_cvariance); kernel.Append("}"); } break; case SeqType.MPL_SEQ_MIN: kernel.Append("if (p->c_n==1) p->c_calc = newd; else if (p->c_calc>newd) { p->c_calc = newd; p->c_resx = p->c_x; p->c_resn = p->c_n; };"); //if (p.c_n==1) p.c_calc=newd; else if (p.c_calc>newd) { p.c_calc = newd; p.c_resx = p.c_x; p.c_resn = p.c_n; } break; case SeqType.MPL_SEQ_MAX: kernel.Append("if (p->c_n==1) p->c_calc = newd; else if (p->c_calc<newd) { p->c_calc = newd; p->c_resx = p->c_x; p->c_resn = p->c_n; };"); // if (p.c_n==1) p.c_calc=newd; else if (p.c_calc<newd) { p.c_calc = newd; p.c_resx = p.c_x; p.c_resn = p.c_n; } break; case SeqType.MPL_SEQ_DELTA: kernel.Append("p->c_calc = newd-p->c_calc;"); //p.c_calc = newd-p.c_calc; break; default: kernel.Append("p->c_calc = newd;"); //p.c_calc = newd; break; } if (p.c_convchktype == ConvCheck.MPL_CONVCHK_REAL) { kernel.AppendFormat(CultureInfo.InvariantCulture,"if (p->c_x.x*p->c_x.x " + (fractdiv ? ">" : "<") + " {0:E}f) p->c_active = 0;", p.c_bailout); /*double ddd = p.c_x.Real*p.c_x.Real; if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false;*/ } else if (p.c_convchktype == ConvCheck.MPL_CONVCHK_IMAG) { kernel.AppendFormat(CultureInfo.InvariantCulture, "if (p->c_x.y*p->c_x.y " + (fractdiv ? ">" : "<") + " {0:E}f) p->c_active = 0;", p.c_bailout); /*double ddd = p.c_x.Imaginary*p.c_x.Imaginary; if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false;*/ } else if (p.c_convchktype == ConvCheck.MPL_CONVCHK_OR) { kernel.AppendFormat(CultureInfo.InvariantCulture, "if ((p->c_x.y*p->c_x.y " + (fractdiv ? ">" : "<") + " {0:E}f) || (p->c_x.x*p->c_x.x " + (fractdiv ? ">" : "<") + " {0:E}f)) p->c_active = 0;", p.c_bailout); /*if ((fractdiv) && ((p.c_x.Real*p.c_x.Real>p.c_bailout) || (p.c_x.Imaginary*p.c_x.Imaginary>p.c_bailout))) p.c_active = false; if (!(fractdiv) && ((p.c_x.Real*p.c_x.Real<p.c_bailout) || (p.c_x.Imaginary*p.c_x.Imaginary<p.c_bailout))) p.c_active = false;*/ } else if (p.c_convchktype == ConvCheck.MPL_CONVCHK_AND) { kernel.AppendFormat(CultureInfo.InvariantCulture, "if ((p->c_x.y*p->c_x.y " + (fractdiv ? ">" : "<") + " {0:E}f) && (p->c_x.x*p->c_x.x " + (fractdiv ? ">" : "<") + " {0:E}f)) p->c_active = 0;", p.c_bailout); /*if ((fractdiv) && ((p.c_x.Real*p.c_x.Real>p.c_bailout) && (p.c_x.Imaginary*p.c_x.Imaginary>p.c_bailout))) p.c_active = false; if (!(fractdiv) && ((p.c_x.Real*p.c_x.Real<p.c_bailout) && (p.c_x.Imaginary*p.c_x.Imaginary<p.c_bailout))) p.c_active = false;*/ } else if (p.c_convchktype == ConvCheck.MPL_CONVCHK_MANH) { kernel.AppendFormat(CultureInfo.InvariantCulture, "if ( ((ABS(p->c_x.y)+ABS(p->c_x.x))*((ABS(p->c_x.y)+ABS(p->c_x.x))) " + (fractdiv ? ">" : "<") + " {0:G}f)) p->c_active = 0;", p.c_bailout); /*double ddd = (absval(p.c_x.Imaginary)+absval(p.c_x.Real))*(absval(p.c_x.Imaginary)+absval(p.c_x.Real)); if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false;*/ } else if (p.c_convchktype == ConvCheck.MPL_CONVCHK_MANR) { kernel.AppendFormat(CultureInfo.InvariantCulture, "if ( ((p->c_x.y+p->c_x.x)*(p->c_x.y+p->c_x.x)) " + (fractdiv ? ">" : "<") + " {0:E}f)) p->c_active = 0;", p.c_bailout); /*double ddd = (p.c_x.Real+p.c_x.Imaginary)*(p.c_x.Real+p.c_x.Imaginary); if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false; */ } else { kernel.AppendFormat(CultureInfo.InvariantCulture, "if (NORM(p->c_x) " + (fractdiv ? ">" : "<") + " {0:E}f) p->c_active = 0;", p.c_bailout); /*double ddd = p.c_x.Norm(); if ((fractdiv) && ( ddd>p.c_bailout)) p.c_active = false; if (!(fractdiv) && ( ddd<p.c_bailout)) p.c_active = false;*/ } kernel.AppendFormat(CultureInfo.InvariantCulture, "if (p->c_n>{0}) {{ p->c_active = 0; p->c_isin = 1; }}", p.c_nlimit); //if (p.c_n>p.c_nlimit) { p.c_active = false; p.c_isin = true; } if (p.c_checktype == SeqCheck.MPL_CHECK_TRIANGLE_SMOOTH) { throw new NotImplementedException("Smooth triangle algorithm is unavailable in this CalculatorFactory"); /*if (p.c_active == false) if (!p.c_isin) { p.c_oldx = p.c_x; p.c_x = Fractal_Mandel(p.c_x,c); p.c_n++; double newxnorm = p.c_oldx.Norm(); double lowbound = absval(newxnorm-trinorm); if ((newxnorm+trinorm-lowbound)==0) newd=0; else newd = (p.c_x.Magnitude-lowbound)/(newxnorm+trinorm-lowbound); p.c_calc += newd; double oldsum = p.c_calc/(p.c_n+1); double il2=1/Math.Log(2); double lp=Math.Log(Math.Log(p.c_bailout)); double f=il2*lp-il2*Math.Log(Math.Log(Complex.Abs(p.c_x)))+2; double az2 = p.c_x.Norm(); p.c_oldx = p.c_x; p.c_x = Fractal_Mandel(p.c_oldx,c); lowbound = absval(az2-trinorm); if ((az2+trinorm-lowbound)!=0) p.c_calc+=(Complex.Abs(p.c_x)-lowbound)/(az2+trinorm-lowbound); p.c_n++; p.c_calc = p.c_calc/(p.c_n+1); p.c_calc = oldsum+(p.c_calc-oldsum)*(f-1); } else { p.c_calc /= p.c_n+1; }*/ } else if (p.c_checkseqtype == SeqType.MPL_SEQ_MEAN) { kernel.Append("if (p->c_active == 0) p->c_calc /= (float)p->c_n+1.0f;"); //if (p.c_active == false) p.c_calc /= p.c_n+1; } if (p == deflayer) { kernel.Append("if (p->c_active == 0) end = 1;"); /*if (!deflayer.c_active) end = true; */ } kernel.Append("}"); } kernel.Append("x = newx; }"); for (int i = 0; i < LayerData.Count; i++) { kernel.Append("out_p"+i+"[index] = p"+i+";"); //kernel.Append("out_p" + i + "[index].c_calc = 52.0f;"); } kernel.Append("}"); //System.Console.WriteLine(kernel.Replace(";", ";\n").Replace("}","}\n")); //kernel.Clear(); //kernel.Append(@"kernel void VectorAdd(global read_only float* a,global read_only float* b,global write_only float* c ){int index = get_global_id(0);c[index] = a[index] + b[index];}"); ComputeProgram prg = new ComputeProgram(_context, kernel.Replace(";", ";\n").Replace("}","}\n").ToString()); try { prg.Build(null, null, null, IntPtr.Zero); } catch (ComputeException e) { throw new Exception("Error while building: " + prg.GetBuildLog(_context.Devices[0]), e); } ComputeKernel krnl = prg.CreateKernel("FractalCalc"); return new OpenCLCalculator(_context,prg,krnl); }