Ejemplo n.º 1
0
        public ExportImage(FractalParameters fp, RenderingParameters rp)
        {
            _fractalP = fp;
            _renderP = rp;

            InitializeComponent();

            txtViewPosX.Text = _fractalP.viewPort.X.ToString();
            txtViewPosY.Text = _fractalP.viewPort.Y.ToString();
            txtViewWidth.Text = _fractalP.viewPort.Width.ToString();
            txtViewHeight.Text = _fractalP.viewPort.Height.ToString();
        }
Ejemplo n.º 2
0
        /**
         * Generate the data. return true if the Image property has been changed.
         **/
        public bool generate(FractalParameters fp, CancellationToken? ct)
        {
            bool innerDataChanged = false;

            // default value
            ParallelOptions po = new ParallelOptions();
            if (ct != null)
                po.CancellationToken = (CancellationToken)ct;

            // If the size of the generation has changed or if it is the first generation
            if (_tabResultComputation == null || fp.width != _width || fp.height != _height)
            {
                init(fp.width, fp.height);
                innerDataChanged = true;
            }

            float mulX = fp.viewPort.Width / (float)fp.width;
            float mulY = fp.viewPort.Height / (float)fp.height;
            float baseX = (float)fp.viewPort.X;
            float baseY = (float)fp.viewPort.Y;
            int bailout;
            int maxIter;

            if (fp.highQuality)
            {
                bailout = 1000;
                maxIter = 3000;
            }
            else
            {
                bailout = 2;
                maxIter = 255;
            }

            po.CancellationToken.ThrowIfCancellationRequested();

            try
            {
                Parallel.For(0, _height, po, j =>
                {
                    Complex z, c;
                    switch (fp.type)
                    {
                            // TODO: Ugly, create a Fractal object subclassed by JULIA, MANDELBROT et al.
                            // with : "Name", "Values(line)" (to limit the number of function call), etc.
                        case FractalType.BURNING_SHIP:
                            c._imag = j * mulY + baseY;
                            for (int i = 0; i < _width; i++)
                            {
                                c._real = i * mulX + baseX;
                                setValAt(i, j, ComputeAbsValAt(c, fp.highQuality, bailout, maxIter));
                            }
                            break;
                        case FractalType.MANDELBROT:
                            z = new Complex(0, 0);
                            c._imag = j * mulY + baseY;
                            for (int i = 0; i < _width; i++)
                            {
                                c._real = i * mulX + baseX;
                                setValAt(i, j, ComputeValAt(z, c, fp.highQuality, bailout, maxIter));
                            }
                            break;
                        case FractalType.JULIA:
                            c = fp.c;
                            z._imag = j * mulY + baseY;
                            for (int i = 0; i < _width; i++) {
                                z._real = i * mulX + baseX;
                                setValAt(i, j, ComputeValAt(z, c, fp.highQuality, bailout, maxIter));
                            }
                            break;
                        default:
                            throw new System.NotImplementedException(fp.type + "is not implemented");
                    }

                });
            }
            catch (OperationCanceledException e) { throw e; }

            return innerDataChanged;
        }