Example #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;
            }

            buttonRenderAnim.Enabled = false;
            buttonRender.Enabled     = false;
            buttonRes.Enabled        = false;
            buttonStop.Enabled       = true;
            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;

            if (scene == null)
            {
                scene = FormSupport.getScene();         // scene prototype
            }
            // Start main rendering thread:
            aThread = new Thread(new ThreadStart(this.RenderAnimation));
            aThread.Start();
        }
Example #2
0
        /// <summary>
        /// Redraws the whole image.
        /// </summary>
        private void RenderImage()
        {
            Cursor.Current = Cursors.WaitCursor;

            buttonRender.Enabled     = false;
            buttonRenderAnim.Enabled = false;
            buttonRes.Enabled        = false;

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

            if (scene == null)
            {
                scene = FormSupport.getScene();         // scene prototype
            }
            IImageFunction imf = FormSupport.getImageFunction(scene);

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

            IRenderer rend = FormSupport.getRenderer(imf, superSampling);

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

            // animation:
            ITimeDependent sc = scene as ITimeDependent;

            if (sc != null)
            {
                sc.Time = (double)numTime.Value;
            }
            MT.InitThreadData();

            Stopwatch sw = new Stopwatch();

            sw.Start();

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

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

            setImage(ref outputImage, newImage);

            buttonRender.Enabled     = true;
            buttonRenderAnim.Enabled = true;
            buttonRes.Enabled        = true;

            Cursor.Current = Cursors.Default;
        }