コード例 #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)
        {
            if (imf == null)
            {
                imf  = FormSupport.getImageFunction(FormSupport.getScene());
                rend = null;
            }

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

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

            if (height <= 0)
            {
                height = panel1.Height;
            }
            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;
            }

            double[] color = new double[3];
            long     hash  = imf.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
        /// <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);

            if (imf == null)
            {
                imf  = FormSupport.getImageFunction(FormSupport.getScene());
                rend = null;
            }
            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;
            }

            if (rend == null)
            {
                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;
            }
            progress.SyncInterval = ((width * (long)height) > (2L << 20)) ? 30000L : 10000L;
            progress.Reset();
            CSGInnerNode.ResetStatistics();

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

            if (checkMultithreading.Checked && Environment.ProcessorCount > 1)
            {
                Thread[] pool = new Thread[Environment.ProcessorCount];
                int      t;
                for (t = 0; t < pool.Length; t++)
                {
                    pool[t] = new Thread(new ParameterizedThreadStart(this.RenderWorker));
                }
                for (t = pool.Length; --t >= 0;)
                {
                    pool[t].Start(new WorkerThreadInit(newImage, width, height, t, pool.Length));
                }

                for (t = 0; t < pool.Length; t++)
                {
                    pool[t].Join();
                    pool[t] = null;
                }
            }
            else
            {
                MT.InitThreadData();
                rend.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}, f{3:#,#}, mt{4}, r{5:#,#}k, i{6:#,#}k, bb{7:#,#}k, t{8:#,#}k ]",
                                       1.0e-3 * elapsed, width, height, CSGInnerNode.countFaces,
                                       checkMultithreading.Checked ? Environment.ProcessorCount : 1,
                                       (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();
        }