Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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;
     }
 }
Esempio n. 3
0
 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 });
 }
Esempio n. 4
0
        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"));
        }
Esempio n. 5
0
 /// <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;
 }
Esempio n. 6
0
 public void Remove(IFractal fractal)
 {
     if (_canRemoveFractals)
     {
         _document.RemoveFractal(fractal);
     }
 }
Esempio n. 7
0
 public Renderer()
 {
     this.palette     = ColorsManager.LoadPalette();
     this.MyBitmap    = new Bitmap(Constants.BitmapWidth, Constants.BitmapHeight);
     this.mandel      = new Mandelbrot();
     this.renderTimer = new Stopwatch();
 }
Esempio n. 8
0
 /// <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 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();
        }
Esempio n. 12
0
 protected virtual void OnSelectedChanged(IFractal fractal)
 {
     if (SelectedChanged != null)
     {
         SelectedChanged(this, new FractalLibrary.Events.FractalEventArgs(fractal));
     }
 }
Esempio n. 13
0
        /// <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));
        }
Esempio n. 14
0
 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;
 }
Esempio n. 16
0
 public BoxDimensionCalculator(IFractal fractal, float delta)
 {
     if (fractal == null)
     {
         throw new ArgumentNullException("fractal == null");
     }
     _fractal = fractal;
     _delta   = delta;
 }
Esempio n. 17
0
        /// <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;
        }
Esempio n. 18
0
        /// <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();
     }
 }
Esempio n. 20
0
        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;;
        }
Esempio n. 21
0
        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
            });
        }
 private void SetFractalIfRequired(
     string startSystemСondition,
     string rotateAngle,
     string generativeRules)
 {
     _fractal = FractalBuilder.Get2DLSystemFractal(
         startSystemСondition: startSystemСondition,
         rotateAngle: int.Parse(rotateAngle),
         generativeRules: generativeRules);
 }
Esempio n. 23
0
        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)));
        }
Esempio n. 24
0
        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();
        }
Esempio n. 25
0
        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)");
        }
Esempio n. 27
0
 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]);
 }
Esempio n. 28
0
        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)];
        }
Esempio n. 29
0
 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));
     }
 }
Esempio n. 30
0
        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
                {
                }
            });
        }
Esempio n. 32
0
        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);
        }
Esempio n. 33
0
 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();
                 }
             }
         }
     }
 }
Esempio n. 34
0
        /// <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);
        }
Esempio n. 35
0
        /// <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));
        }
Esempio n. 36
0
 /// <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);
 }
Esempio n. 37
0
 /// <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;
 }
Esempio n. 38
0
 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;
 }