Example #1
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;
        }
Example #2
0
        /// <summary>
        /// Worker thread (picks up individual frames and renders them one by one).
        /// </summary>
        protected void RenderWorker()
        {
            // thread-specific data:
            ITimeDependent datatd = data as ITimeDependent;
            object         myData = (datatd == null) ? data : datatd.Clone();

            MT.InitThreadData();

            IImageFunction imf = FormSupport.getImageFunction(textParam.Text, myData);

            imf.Width  = width;
            imf.Height = height;
            ITimeDependent imftd = imf as ITimeDependent;

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

            rend.Width        = width;
            rend.Height       = height;
            rend.Adaptive     = 0;          // turn off adaptive bitmap synthesis completely (interactive preview not needed)
            rend.ProgressData = progress;

            // worker loop:
            while (true)
            {
                double myTime;
                int    myFrameNumber;

                lock ( progress )
                {
                    if (!progress.Continue ||
                        time > end)
                    {
                        sem.Release();      // chance for the main animation thread to give up as well..
                        return;
                    }

                    // got a frame to compute:
                    myTime        = time;
                    time         += dt;
                    myFrameNumber = frameNumber++;
                }

                // set up the new result record:
                Result r = new Result();
                r.image       = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                r.frameNumber = myFrameNumber;

                // set specific time to my image function:
                if (imftd != null)
                {
                    imftd.Time = myTime;
                }

                // render the whole frame:
                rend.RenderRectangle(r.image, 0, 0, width, height);

                // ... and put the result into the output queue:
                lock ( queue )
                {
                    queue.Enqueue(r);
                }
                sem.Release();              // notify the main animation thread
            }
        }