Пример #1
0
        /// <summary>
        /// Shoots single primary ray only..
        /// </summary>
        /// <param name="x">X-coordinate inside the raster image.</param>
        /// <param name="y">Y-coordinate inside the raster image.</param>
        private void singleSample(int x, int y)
        {
            // determine output image size:
            int width = ImageWidth;

            if (width <= 0)
            {
                width = panel1.Width;
            }
            int height = ImageHeight;

            if (height <= 0)
            {
                height = panel1.Height;
            }

            if (dirty || imfs == null)
            {
                imfs  = getImageFunction(FormSupport.getScene(), width, height);
                dirty = false;
            }

            double[] color = new double[3];
            MT.InitThreadData();
            long hash = imfs.GetSample(x + 0.5, y + 0.5, color);

            labelSample.Text = string.Format(CultureInfo.InvariantCulture, "Sample at [{0},{1}] = [{2:f},{3:f},{4:f}], {5:X}",
                                             x, y, color[0], color[1], color[2], hash);
        }
Пример #2
0
        public Form1(string[] args)
        {
            singleton = this;
            InitializeComponent();
            progress = new RenderingProgress(this);

            // Init scenes etc.
            string name;

            FormSupport.InitializeScenes(args, out name);
            Text += " (rev: " + rev + ") '" + name + '\'';

            buttonRes.Text = FormResolution.GetLabel(ref ImageWidth, ref ImageHeight);
        }
Пример #3
0
        private IImageFunction getImageFunction(IRayScene sc, int width, int height)
        {
            IImageFunction imf = FormSupport.getImageFunction(sc);

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

            RayTracing rt = imf as RayTracing;

            if (rt != null)
            {
                rt.DoShadows     = checkShadows.Checked;
                rt.DoReflections = checkReflections.Checked;
                rt.DoRefractions = checkRefractions.Checked;
            }

            return(imf);
        }
Пример #4
0
        private IRenderer getRenderer(IImageFunction imf, int width, int height)
        {
            IRenderer rend = FormSupport.getRenderer(imf);

            rend.Width        = width;
            rend.Height       = height;
            rend.Adaptive     = 8;
            rend.ProgressData = progress;

            SupersamplingImageSynthesizer ss = rend as SupersamplingImageSynthesizer;

            if (ss != null)
            {
                ss.Supersampling = (int)numericSupersampling.Value;
                ss.Jittering     = checkJitter.Checked ? 1.0 : 0.0;
            }

            return(rend);
        }
Пример #5
0
        /// <summary>
        /// [Re]-renders the whole image (in separate thread).
        /// </summary>
        private void RenderImage()
        {
            Cursor.Current = Cursors.WaitCursor;

            // determine output image size:
            int width = ImageWidth;

            if (width <= 0)
            {
                width = panel1.Width;
            }
            int height = ImageHeight;

            if (height <= 0)
            {
                height = panel1.Height;
            }

            Bitmap newImage = new Bitmap(width, height, PixelFormat.Format24bppRgb);

            int threads = checkMultithreading.Checked ? Environment.ProcessorCount : 1;
            int t; // thread ordinal number

            IRenderer[] rend = new IRenderer[threads];

            // separate renderer, image function and the scene for each thread (safety precaution)
            for (t = 0; t < threads; t++)
            {
                rend[t] = getRenderer(getImageFunction(FormSupport.getScene(), width, height), width, height);
            }

            progress.SyncInterval = ((width * (long)height) > (2L << 20)) ? 30000L : 10000L;
            progress.Reset();
            CSGInnerNode.ResetStatistics();

            lock ( sw )
            {
                sw.Reset();
                sw.Start();
            }

            if (threads > 1)
            {
                Thread[] pool = new Thread[threads];
                for (t = 0; t < threads; t++)
                {
                    pool[t] = new Thread(new ParameterizedThreadStart(RenderWorker));
                }
                for (t = threads; --t >= 0;)
                {
                    pool[t].Start(new WorkerThreadInit(rend[t], newImage, width, height, t, threads));
                }

                for (t = 0; t < threads; t++)
                {
                    pool[t].Join();
                    pool[t] = null;
                }
            }
            else
            {
                MT.InitThreadData();
                rend[0].RenderRectangle(newImage, 0, 0, width, height);
            }

            long elapsed;

            lock ( sw )
            {
                sw.Stop();
                elapsed = sw.ElapsedMilliseconds;
            }

            string msg = string.Format(CultureInfo.InvariantCulture, "{0:f1}s  [ {1}x{2}, mt{3}, r{4:#,#}k, i{5:#,#}k, bb{6:#,#}k, t{7:#,#}k ]",
                                       1.0e-3 * elapsed, width, height, threads,
                                       (Intersection.countRays + 500L) / 1000L,
                                       (Intersection.countIntersections + 500L) / 1000L,
                                       (CSGInnerNode.countBoundingBoxes + 500L) / 1000L,
                                       (CSGInnerNode.countTriangles + 500L) / 1000L);

            SetText(msg);
            Console.WriteLine("Rendering finished: " + msg);
            SetImage(newImage);

            Cursor.Current = Cursors.Default;

            StopRendering();
        }