Exemplo n.º 1
0
        /// <summary>
        /// Animation rendering prolog: prepare all the global (uniform) values, start the main thread.
        /// </summary>
        private void buttonRenderAnim_Click(object sender, EventArgs e)
        {
            if (aThread != null)
            {
                return;
            }

            SetGui(false);
            lock ( progress )
            {
                progress.Continue = true;
            }

            // Global animation properties (it's safe to access GUI components here):
            time = (double)numFrom.Value;
            end  = (double)numTo.Value;
            if (end <= time)
            {
                end = time + 1.0;
            }
            double fps = (double)numFps.Value;

            dt          = (fps > 0.0) ? 1.0 / fps : 25.0;
            end        += 0.5 * dt;
            frameNumber = 0;

            width = ImageWidth;
            if (width <= 0)
            {
                width = panel1.Width;
            }
            height = ImageHeight;
            if (height <= 0)
            {
                height = panel1.Height;
            }
            superSampling = (int)numericSupersampling.Value;

            // param string:
            Dictionary <string, string> p = Util.ParseKeyValueList(textParam.Text);

            if (p.Count > 0)
            {
                // output file-name prefix:
                if (!p.TryGetValue("prefix", out prefix))
                {
                    prefix = "out";
                }
            }

            if (data == null)
            {
                data = FormSupport.getData(textParam.Text);         // animation data
            }
            // Start main rendering thread:
            aThread = new Thread(new ThreadStart(this.RenderAnimation));
            aThread.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Redraws the whole image.
        /// </summary>
        private void RenderImage()
        {
            Cursor.Current = Cursors.WaitCursor;

            SetGui(false);

            width = ImageWidth;
            if (width <= 0)
            {
                width = panel1.Width;
            }
            height = ImageHeight;
            if (height <= 0)
            {
                height = panel1.Height;
            }
            superSampling = (int)numericSupersampling.Value;
            Bitmap im = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            MT.InitThreadData();

            if (data == null)
            {
                data = FormSupport.getData(textParam.Text);           // animation data
            }
            IImageFunction imf = FormSupport.getImageFunction(textParam.Text, data);

            imf.Width  = width;
            imf.Height = height;

            IRenderer rend = FormSupport.getRenderer(textParam.Text, imf);

            rend.Width        = width;
            rend.Height       = height;
            rend.Adaptive     = 0;
            rend.ProgressData = progress;
            progress.Continue = true;

            // animation:
            ITimeDependent imftd = imf as ITimeDependent;

            if (imftd != null)
            {
                imftd.Time = (double)numTime.Value;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            rend.RenderRectangle(im, 0, 0, width, height);

            sw.Stop();
            labelElapsed.Text = string.Format(CultureInfo.InvariantCulture, "Elapsed: {0:f1}s", 1.0e-3 * sw.ElapsedMilliseconds);

            SetImage((Bitmap)im.Clone());

            string fileName = Util.FileNameString(textParam.Text) + ".png";

            im.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            im.Dispose();

            SetGui(true);

            Cursor.Current = Cursors.Default;
        }