public List <IFractal> Load() { if (string.IsNullOrEmpty(_filePath)) { throw new ArgumentException("string.IsNullOrEmpty(filePath)"); } if (!File.Exists(_filePath)) { throw new FileNotFoundException(_filePath); } List <IFractal> fractals = new List <IFractal>(); XmlDocument doc = new XmlDocument(); doc.Load(_filePath); var fractalsRoot = doc["fractals"]; XmlNodeList fractalNodes = fractalsRoot.SelectNodes("fractal"); FractalCompiler fractalCompiler = new FractalCompiler(); foreach (XmlNode fractalNode in fractalNodes) { IFractal fractal = fractalCompiler.CompileFromXml(fractalNode.OuterXml); fractals.Add(fractal); } return(fractals); }
public void ShowFractal(IFractal fractal, IControlPanel controlPanel) { if (MainViewPresenter != null) { FractalCompositeView2 compositeView = new FractalCompositeView2(); compositeView.FractalView = MainViewPresenter.RendererAbstractFactory.CreateFractalView(); InitFractalCompositeView(fractal, compositeView, controlPanel); compositeView.Text = fractal.Name; compositeView.Dock = DockStyle.Fill; compositeView.Activated += (s, e) => { var dockContent = s as IDockContent; if (dockContent == null) { return; } if (fractal != null) { OnSelectedChanged(fractal); } }; compositeView.FormClosed += compositeViewClosed; compositeView.Show(_dockPanel); _dockContentFractalDictionary[compositeView] = fractal; } }
public void LoadAsync(IFractal fractal, Bounds bounds) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += RunFractalLoad; IsLoading = true; worker.RunWorkerAsync(new AsyncLoadArgs { Bounds = bounds, Fractal = fractal, Renderer = renderer }); }
protected IActionResult FractalImage(IFractal fractal, int z, long x, long y, int shades) { var generator = new TileGenerator(fractal, shades, z, x, y); generator.Palette = DefaultPalette(); return(File(generator.GetImageStream(), "image/png")); }
/// <summary>Precomputed values used during the rendering to speed up calculations.</summary> private void PrecomputeValues(IFractal fractal, Bounds bounds) { xIncrement = bounds.Width / width; yIncrement = bounds.Height / height; minBoundsX = bounds.X.MinValue; minBoundsY = bounds.Y.MinValue; }
public void Remove(IFractal fractal) { if (_canRemoveFractals) { _document.RemoveFractal(fractal); } }
public Renderer() { this.palette = ColorsManager.LoadPalette(); this.MyBitmap = new Bitmap(Constants.BitmapWidth, Constants.BitmapHeight); this.mandel = new Mandelbrot(); this.renderTimer = new Stopwatch(); }
public OpenGLFractalViewPresenter( IFractal fractal, IControlPanel controlPanel, IFractalView fractalView, IFractalRenderer renderer) : base(fractal, controlPanel, fractalView, renderer) { }
public MandelbrotSetRunner(ILogger <MandelbrotSetRunner> logger, IFractal fractal) { _logger = logger; _fractal = fractal; _logger.LogInformation("MandelbrotSet http://warp.povusers.org/Mandelbrot/"); }
public FractalCalculatorViewPresenter(IFractal fractal, IDimensionCalculatorFactory dimensionCalculatorFactory, IFractalCalculatorView fractalCalculatorView, IControlPanel controlPanel) { if (fractal == null) { throw new ArgumentNullException("fractal"); } if (dimensionCalculatorFactory == null) { throw new ArgumentNullException("dimensionCalculatorFactory"); } if (fractalCalculatorView == null) { throw new ArgumentNullException("fractalCalculatorView"); } if (controlPanel == null) { throw new ArgumentNullException("controlPanel"); } _fractal = fractal; _dimensionCalculatorFactory = dimensionCalculatorFactory; _fractalCalculatorView = fractalCalculatorView; _controlPanel = controlPanel; _fractalCalculatorView.ClearPoints += new EventHandler(_fractalCalculatorView_ClearPoints); _fractalCalculatorView.CalculatePoints += new EventHandler(_fractalCalculatorView_CalculatePoints); _fractalCalculatorView.ResetControlPanel += new EventHandler(_fractalCalculatorView_ResetControlPanel); _fractalCalculatorView.CalculateDimension += new EventHandler(_fractalCalculatorView_CalculateDimension); _fractalCalculatorView.ValidatingUI += new Events.ValidatingEventHandler(_fractalCalculatorView_Validating); InitValidators(); }
protected virtual void OnSelectedChanged(IFractal fractal) { if (SelectedChanged != null) { SelectedChanged(this, new FractalLibrary.Events.FractalEventArgs(fractal)); } }
/// <summary> /// Gets a RenderedFractal by rendering the fractal with the area to render. /// /// The bounds will be scaled to match the ImageProvider dimensions. /// </summary> public RenderedFractal Render(IFractal fractal, Bounds areaToRender) { var bounds = GetResizedBounds(areaToRender); var renderedFractal = fractalProcessor.Process(fractal, bounds, ImageProvider.Dimensions); return(Render(renderedFractal)); }
private void _document_Changed(object sender, EventArgs e) { if (_document.IsDirty && !_showingIsDirty) { _mainView.ShowDocumentIsDirty(); _showingIsDirty = true; } else if (!_document.IsDirty && _showingIsDirty) { _mainView.ShowDocumentIsClean(); _showingIsDirty = false; } if (_document.Fractals.Count == 0) { _mainView.ClearAll(); _viewStatus.Clear(); _selected = null; RefreshMainView(); } foreach (IFractal fractal in _document.Fractals) { if (!_viewStatus.ContainsKey(fractal)) { AddTab(fractal); } } }
public FractalEventArgs(IFractal fractal) { if (fractal == null) { throw new ArgumentNullException("fractal"); } _fractal = fractal; }
public BoxDimensionCalculator(IFractal fractal, float delta) { if (fractal == null) { throw new ArgumentNullException("fractal == null"); } _fractal = fractal; _delta = delta; }
/// <summary>Sets a point on the image to the result of testing the point on the fractal.</summary> private void SetPoint(float[] buffer, IFractal fractal, int x, int y) { var transformedX = xIncrement * x + minBoundsX; var transformedY = yIncrement * y + minBoundsY; var iterations = fractal.TestPoint(transformedX, transformedY); buffer[(y * width) + x] = iterations; }
public void RemoveFractal(IFractal fractal) { if (_fractals.Contains(fractal)) { //throw new ArgumentException("!_fractals.Contains(fractal)"); _fractals.Remove(fractal); _isDirty = true; OnChanged(); } }
public Screen(Graphics inG, IFractal inFractal, Form inForm) { g = inG; fractal = inFractal; form = inForm; PictureBox picturebox = (PictureBox)form.Controls.Find("pictureBox1", true)[0]; width = picturebox.Width; height = picturebox.Height;; }
private void SetFractalIfRequired( string startSystemСondition, string rotateAngle, string generativeRules) { _fractal = FractalBuilder.Get2DLSystemFractal( startSystemСondition: startSystemСondition, rotateAngle: int.Parse(rotateAngle), generativeRules: generativeRules); }
public double CalculateDimension(IFractal fractal, float delta) { if (fractal == null) { throw new ArgumentNullException("fractal == null"); } List <PointF> points = fractal.Points; double numOfDeltaMeshCubes = (double)GetNumOfDeltaMeshCubesIntersectingFractal(points, delta); return(Math.Log(numOfDeltaMeshCubes) / (-1 * Math.Log((double)delta))); }
public Form1() { InitializeComponent(); bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height); gBitmap = Graphics.FromImage(bitmap); Pen p = new Pen(Color.Blue); fractal = new Mandlebrot(); screen = new Screen(g, fractal, this); g = this.CreateGraphics(); }
public override void Render(IFractal fractal, IControlPanel controlPanel) { lock (_syncRendering) { int vbo = -1; RectangleF rectangle = controlPanel.Rectangle; try { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.EnableVertexAttribArray(0);//Enable vertex array attribute //If points are cached, use them without recreating them var points = fractal.Points; if (points.Count == 0) { return; } if (_chachedVertices == null || _chachedVertices.Length != points.Count || _chachedVertices[points.Count - 1].X != points[points.Count - 1].X || _chachedVertices[points.Count - 1].Y != points[points.Count - 1].Y) { //var points = fractal.Points; _chachedVertices = new Vector2[points.Count]; int i = 0; foreach (var p in points) { _chachedVertices[i] = new Vector2(p.X, p.Y); i++; } } //Apply trnasformations in OpenGL GL.Scale(controlPanel.Zoom / 1000.0, controlPanel.Zoom / 1000.0, 1); GL.Rotate(controlPanel.AnticlockWiseRotation, Vector3.UnitZ); GL.Translate(controlPanel.XTranslation / 100.0, controlPanel.YTranslation / 100.0, 0); GL.GenBuffers(1, out vbo); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); GL.BufferData <Vector2>(BufferTarget.ArrayBuffer, new IntPtr(_chachedVertices.Length * Vector2.SizeInBytes), _chachedVertices, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 0, 0); GL.DrawArrays(PrimitiveType.Points, 0, _chachedVertices.Length); } finally { GL.DisableVertexAttribArray(0); GL.Flush(); GL.DeleteBuffer(vbo); } } }
private void RenderSingleFrame(IFractal fractal, FractalImageConfig fractalImageConfig) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); fractal.InitFrame(fractalImageConfig.Width, fractalImageConfig.Height, fractalImageConfig.MaxItr); fractal.RenderFrame(fractalImageConfig.MinRe, fractalImageConfig.MaxRe, fractalImageConfig.MinIm); fractal.SaveFrame(fractalImageConfig.Name); stopWatch.Stop(); _logger.LogInformation($"Frame generation took {stopWatch.ElapsedMilliseconds / 1000} sec ({stopWatch.ElapsedMilliseconds} ms)"); }
private void AddTab(IFractal fractal) { if (!_viewStatus.ContainsKey(fractal)) { var tmpControlPanel = new ControlPanel(); tmpControlPanel.XTranslation = 500; tmpControlPanel.YTranslation = 100; tmpControlPanel.AnticlockWiseRotation = 0; tmpControlPanel.Zoom = 100; _viewStatus.Add(fractal, tmpControlPanel); } _mainView.ShowFractal(fractal, _viewStatus[fractal]); }
private void UpdateSelectedFractal() { var dict = new Dictionary <Tuple <FractalType, bool>, IFractal> { { Tuple.Create(FractalType.MandelbrotSet, true), _mandelbrotSetGpuDouble }, { Tuple.Create(FractalType.MandelbrotSet, false), _mandelbrotSetGpuFloat }, { Tuple.Create(FractalType.JuliaSet, true), _juliaSetGpuDouble }, { Tuple.Create(FractalType.JuliaSet, false), _juliaSetGpuFloat }, { Tuple.Create(FractalType.BarnsleyFern, true), _barnsleyFern }, { Tuple.Create(FractalType.BarnsleyFern, false), _barnsleyFern } }; _selectedFractal = dict[Tuple.Create(_fractalType, _isGpuDataTypeDouble)]; }
private void InitFractalCompositeView(IFractal fractal, FractalCompositeView2 view, IControlPanel controlPanel) { if (MainViewPresenter != null) { int pointsToCalculate = 100000;//TODO should be moved controlPanel.Rectangle = view.FractalView.DrawableRectangle; view.FractalCalculatorView.RefreshView(pointsToCalculate); FractalCalculatorViewPresenter presenter3 = new FractalCalculatorViewPresenter(fractal, MainViewPresenter.DimensionCalculatorFactory, view.FractalCalculatorView, controlPanel); FractalViewPresenterBase fractalViewPresenter = MainViewPresenter.RendererAbstractFactory.CreateFractalViewPresenter(fractal, controlPanel, view.FractalView, MainViewPresenter.RendererAbstractFactory.CreateRenderer(view.FractalView)); } }
public TileGenerator(IFractal fractal, int shades, int z, long x, long y) { this.fractal = fractal; this.shades = shades; long n = (long)Math.Pow(2, z); double xScale = (fractal.MaxX - fractal.MinX) / n; double yScale = (fractal.MaxY - fractal.MinY) / n; MinX = fractal.MinX + xScale * x; MaxX = fractal.MinX + xScale * (x + 1); MinY = fractal.MinY + yScale * y; MaxY = fractal.MinY + yScale * (y + 1); }
public override void Render(IFractal fractal, IControlPanel controlPanel) { //Copy for the closure RectangleF rectangle = controlPanel.Rectangle; PointF rotationPoint = controlPanel.RotationPoint; PointF zoomPoint = controlPanel.ZoomPoint; ITransformation transformation = controlPanel.CreateTransformation(); _rendererThread.Enqueue((cancellableArg) => { try { using (Graphics g = _fractalView.CreateViewGraphic()) { g.Clear(Color.White); using (Brush brush = new SolidBrush(Color.Yellow)) { PointF p = transformation.Apply(zoomPoint); g.FillRectangle(brush, p.X, p.Y, 5, 5); } using (Brush brush = new SolidBrush(Color.Orange)) { PointF p = transformation.Apply(rotationPoint); g.FillRectangle(brush, p.X, p.Y, 5, 5); } using (Brush brush = new SolidBrush(Color.Black)) { DrawFractalPoints(brush, transformation, rectangle, fractal, g, cancellableArg); } using (Brush brush = new SolidBrush(Color.Green)) { PointF p = transformation.Apply(zoomPoint); g.FillRectangle(brush, p.X, p.Y, 5, 5); } using (Brush brush = new SolidBrush(Color.DarkOrange)) { PointF p = transformation.Apply(rotationPoint); g.FillRectangle(brush, p.X, p.Y, 5, 5); } } } catch (Exception e)//Catching exception in case the view is closed while still drawing in the panel { } }); }
public FractalImage(IFractal fractal) { if (fractal == null) throw new ArgumentNullException("fractal"); InitializeComponent(); _fractal = fractal; _defaultRange = _fractal.DefaultRange; _maxTries = _fractal.MaxTries; this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw, true); }
public void Select(IFractal selected) { for (int index = _dockPanel.Contents.Count - 1; index >= 0; index--) { if (_dockPanel.Contents[index] is IDockContent) { IDockContent content = (IDockContent)_dockPanel.Contents[index]; if (_dockContentFractalDictionary.ContainsKey(content)) { var fractal = _dockContentFractalDictionary[content]; if (fractal == selected) { content.DockHandler.Activate(); } } } } }
/// <summary>Processes a fractal, computing its values, returning a RenderedFractal.</summary> public RenderedFractal Process(IFractal fractal, Bounds boundsToRender, Dimensions imageDimensions) { width = imageDimensions.Width; height = imageDimensions.Height; PrecomputeValues(fractal, boundsToRender); var buffer = new float[width * height]; Parallel.For(0, height, y => { Parallel.For(0, width, x => { SetPoint(buffer, fractal, x, y); }); }); return new RenderedFractal(buffer, fractal.MaxIterations, boundsToRender, fractal); }
/// <summary>Processes a fractal, computing its values, returning a RenderedFractal.</summary> public RenderedFractal Process(IFractal fractal, Bounds boundsToRender, Dimensions imageDimensions) { width = imageDimensions.Width; height = imageDimensions.Height; PrecomputeValues(fractal, boundsToRender); var buffer = new float[width * height]; Parallel.For(0, height, y => { Parallel.For(0, width, x => { SetPoint(buffer, fractal, x, y); }); }); return(new RenderedFractal(buffer, fractal.MaxIterations, boundsToRender, fractal)); }
/// <summary> /// Gets a RenderedFractal by rendering the fractal with the area to render. /// /// The bounds will be scaled to match the ImageProvider dimensions. /// </summary> public RenderedFractal Render(IFractal fractal, Bounds areaToRender) { var bounds = GetResizedBounds(areaToRender); var renderedFractal = fractalProcessor.Process(fractal, bounds, ImageProvider.Dimensions); return Render(renderedFractal); }
/// <summary>Creates a new RenderedFractal with the data of the fractal.</summary> public RenderedFractal(float[] data, int maxIterations, Bounds bounds, IFractal fractal) : this(data, maxIterations) { Bounds = bounds; Fractal = fractal; }
public FractalVM() { fractal = new FractalP(); C1 = System.Drawing.Color.Green; C2 = k => System.Drawing.Color.FromArgb(k, (int)(k * 0.5) % 255, (int)(k * 1.2) % 255 ); IsMandelbrot = true; }