Exemple #1
0
        public Form1(string[] args)
        {
            singleton = this;
            InitializeComponent();
            progress = new RenderingProgress(this);

            // Init scenes etc.
            FormSupport.InitializeScenes(args, out string name);

            Text     += @" (" + rev + @") '" + name + '\'';
            formTitle = Text;
            SetWindowTitleSuffix(" Zoom: 100%");

            SetOptions(args);
            buttonRes.Text = FormResolution.GetLabel(ref ImageWidth, ref ImageHeight);

            // Placeholder image for PictureBox.
            Image image = Resources.CGG_Logo;

            additionalViews = new AdditionalViews(collectDataCheckBox, Notification);

            additionalViews.Initialize();
            // Makes all maps to initialize again.
            additionalViews.SetNewDimensions(ImageWidth, ImageHeight);

            // Default PaZ button = Right.
            panAndZoom = new PanAndZoomSupport(pictureBox1, image, SetWindowTitleSuffix)
            {
                Button = MouseButtons.Right
            };

            rayVisualizer = new RayVisualizer();
        }
Exemple #2
0
        private IRenderer getRenderer(IImageFunction imf, int width, int height)
        {
            IRenderer rend = FormSupport.getRenderer(imf, (int)NumericSupersampling.Value, CheckJitter.Checked ? 1.0 : 0.0, TextParam.Text);

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

            return(rend);
        }
Exemple #3
0
        private IImageFunction getImageFunction(IRayScene sc, int width, int height)
        {
            IImageFunction imf = FormSupport.getImageFunction(sc, TextParam.Text);

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

            if (imf is RayTracing rt)
            {
                rt.DoShadows     = checkShadows.Checked;
                rt.DoReflections = checkReflections.Checked;
                rt.DoRefractions = checkRefractions.Checked;
                rt.rayRegisterer = new MainRayRegisterer(additionalViews, rayVisualizer);
            }

            return(imf);
        }
Exemple #4
0
        private IImageFunction getImageFunction(IImageFunction imf)
        {
            if (imf == null) // The script didn't define an image-function..
            {
                imf = FormSupport.getImageFunction(TextParam.Text);
            }

            if (imf is RayTracing rt)
            {
                rt.DoShadows     = checkShadows.Checked;
                rt.DoReflections = checkReflections.Checked;
                rt.DoRefractions = checkRefractions.Checked;
                rt.rayRegisterer = new MainRayRegisterer(additionalViews, rayVisualizer);
            }

            return(imf);
        }
Exemple #5
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)
        {
            MT.singleRayTracing = true;
            rayVisualizer.Reset();

            // 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];
            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);

            rayVisualizer.AddingRaysFinished();

            MT.singleRayTracing = false;
        }
Exemple #6
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;

            IRayScene      sc  = FormSupport.getScene();
            IImageFunction imf = getImageFunction(sc, width, height);
            IRenderer      r   = getRenderer(imf, width, height);

            rayVisualizer.UpdateScene(sc);

            master = new Master(newImage, sc, r, RenderClientsForm.instance?.clients, threads, pointCloudCheckBox.Checked, ref AdditionalViews.singleton.pointCloud);
            master.progressData = progress;
            master.InitializeAssignments(newImage, sc, r);

            if (pointCloudCheckBox.Checked)
            {
                master.pointCloud?.SetNecessaryFields(PointCloudSavingStart, PointCloudSavingEnd, Notification, Invoke);
            }

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

            lock (sw)
                sw.Restart();

            master.StartThreads();

            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();
        }
Exemple #7
0
        /// <summary>
        /// [Re]-renders the whole image (in separate thread). OLD VERSION!!!
        /// </summary>
        private void RenderImage_OLD()
        {
            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

            WorkerThreadInit[] wti = new WorkerThreadInit[threads];

            // separate renderer, image function and the scene for each thread (safety precaution)
            for (t = 0; t < threads; t++)
            {
                IRayScene      sc  = FormSupport.getScene();
                IImageFunction imf = getImageFunction(sc, width, height);
                IRenderer      r   = getRenderer(imf, width, height);
                wti[t] = new WorkerThreadInit(r, sc as ITimeDependent, imf as ITimeDependent, newImage, width, height, t, threads);
            }

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

            lock (sw)
                sw.Restart();

            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(wti[t]);
                }

                for (t = 0; t < threads; t++)
                {
                    pool[t].Join();
                    pool[t] = null;
                }
            }
            else
            {
                MT.InitThreadData();
                wti[0].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}, 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();
        }
Exemple #8
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)
        {
            MT.singleRayTracing = true;
            rayVisualizer.Reset();

            // determine output image size:
            ActualWidth = ImageWidth;
            if (ActualWidth <= 0)
            {
                ActualWidth = panel1.Width;
            }
            ActualHeight = ImageHeight;
            if (ActualHeight <= 0)
            {
                ActualHeight = panel1.Height;
            }

            if (dirty || imfs == null)
            {
                int ss = 1;

                // Force preprocess.
                ctx = null;

                _ = FormSupport.getScene(
                    out _, out _,
                    ref ActualWidth,
                    ref ActualHeight,
                    ref ss,
                    TextParam.Text);

                sc = FormSupport.getScene(
                    out imfs,
                    out rend,
                    ref ActualWidth,
                    ref ActualHeight,
                    ref ss,
                    TextParam.Text);

                // IImageFunction.
                if (imfs == null) // not defined in the script
                {
                    imfs = getImageFunction(imfs, sc);
                }
                else
                if (imfs is RayCasting imfray)
                {
                    imfray.Scene = sc;
                }
                imfs.Width  = ActualWidth;
                imfs.Height = ActualHeight;

                // IRenderer.
                if (rend == null) // not defined in the script
                {
                    rend = getRenderer();
                }
                rend.ImageFunction = imfs;
                rend.Width         = ActualWidth;
                rend.Height        = ActualHeight;
                rend.Adaptive      = 0; // 8?
                rend.ProgressData  = progress;

                dirty = false;
            }

            // Set TLS.
            MT.SetRendering(sc, imfs, rend);

            double[] color = new double[3];
            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);

            // Reset TLS.
            MT.ResetRendering();

            rayVisualizer.AddingRaysFinished();

            MT.singleRayTracing = false;
        }
Exemple #9
0
        /// <summary>
        /// [Re]-renders the whole image (in separate thread)
        /// </summary>
        private void RenderImage()
        {
            Cursor.Current = Cursors.WaitCursor;

            // determine output image size:
            ActualWidth = ImageWidth;
            if (ActualWidth <= 0)
            {
                ActualWidth = panel1.Width;
            }

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

            int superSampling = (int)NumericSupersampling.Value;

            // Force preprocessing.
            ctx = null;

            // 1. preprocessing - compute simulation, animation data, etc.
            _ = FormSupport.getScene(
                out _, out _,
                ref ActualWidth,
                ref ActualHeight,
                ref superSampling,
                TextParam.Text);

            // 2. compute regular frame (using the pre-computed context).
            IRayScene scene = FormSupport.getScene(
                out IImageFunction imf,
                out IRenderer rend,
                ref ActualWidth,
                ref ActualHeight,
                ref superSampling,
                TextParam.Text);

            // Update additional views.
            if (collectDataCheckBox.Checked)
            {
                additionalViews.SetNewDimensions(ActualWidth, ActualHeight);
                additionalViews.NewRenderInitialization();
            }
            else if (!additionalViews.mapsEmpty)
            {
                additionalViews.form?.ExportDataButtonsEnabled(true);
            }

            if (ImageWidth > 0) // preserving default (form-size) resolution
            {
                ImageWidth  = ActualWidth;
                ImageHeight = ActualHeight;
                UpdateResolutionButton();
            }
            UpdateSupersampling(superSampling);

            // IImageFunction.
            if (imf == null) // not defined in the script
            {
                imf = getImageFunction(imf, scene);
            }
            else
            if (imf is RayCasting imfray)
            {
                imfray.Scene = scene;
            }
            imf.Width  = ActualWidth;
            imf.Height = ActualHeight;

            // IRenderer.
            if (rend == null) // not defined in the script
            {
                rend = getRenderer();
            }
            rend.ImageFunction = imf;
            rend.Width         = ActualWidth;
            rend.Height        = ActualHeight;
            rend.Adaptive      = 0; // 8?
            rend.ProgressData  = progress;

            // Almost ready for new image computation.
            rayVisualizer.UpdateScene(scene);
            Bitmap newImage = new Bitmap(ActualWidth, ActualHeight, PixelFormat.Format24bppRgb);
            int    threads  = CheckMultithreading.Checked ? Environment.ProcessorCount : 1;

            master = new Master(
                newImage,
                scene,
                imf,
                rend,
                RenderClientsForm.instance?.clients,
                threads,
                pointCloudCheckBox.Checked,
                ref AdditionalViews.singleton.pointCloud);

            master.progressData = progress;
            master.InitializeAssignments(newImage, scene, rend);

            if (pointCloudCheckBox.Checked)
            {
                master.pointCloud?.SetNecessaryFields(PointCloudSavingStart, PointCloudSavingEnd, Notification, Invoke);
            }

            progress.SyncInterval = ((ActualWidth * (long)ActualHeight) > (2L << 20)) ? 3000L : 1000L;
            progress.Reset();
            CSGInnerNode.ResetStatistics();

            lock (sw)
                sw.Restart();

            master.StartThreads();

            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, ActualWidth, ActualHeight, 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();
        }
Exemple #10
0
 private IRenderer getRenderer()
 {
     return(FormSupport.getRenderer((int)NumericSupersampling.Value, CheckJitter.Checked ? 1.0 : 0.0, TextParam.Text));
 }
Exemple #11
0
        /// <summary>
        /// [Re]-renders the whole image (in separate thread). OLD VERSION!!!
        /// </summary>
        private void RenderImage_OLD()
        {
            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
            int superSampling = (int)NumericSupersampling.Value;

            WorkerThreadInit[] wti = new WorkerThreadInit[threads];

            // 1. preprocessing - compute simulation, animation data, etc.
            _ = FormSupport.getScene(true, out _, out _, superSampling, TextParam.Text);

            // Separate renderer, image function and the scene for each thread (safety precaution).
            for (t = 0; t < threads; t++)
            {
                // 2. initialize data for regular frames (using the pre-computed context).
                IRayScene sc = FormSupport.getScene(
                    false,
                    out IImageFunction imf,
                    out IRenderer rend,
                    superSampling,
                    TextParam.Text);

                // IImageFunction.
                imf        = getImageFunction(imf, sc);
                imf.Width  = width;
                imf.Height = height;

                // IRenderer.
                if (rend == null) // not defined in the script
                {
                    rend = getRenderer();
                }
                rend.ImageFunction = imf;
                rend.Width         = width;
                rend.Height        = height;
                rend.Adaptive      = 8;
                rend.ProgressData  = progress;

                wti[t] = new WorkerThreadInit(rend, sc as ITimeDependent, imf as ITimeDependent, newImage, width, height, t, threads);
            }

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

            lock (sw)
                sw.Restart();

            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(wti[t]);
                }

                for (t = 0; t < threads; t++)
                {
                    pool[t].Join();
                    pool[t] = null;
                }
            }
            else
            {
                MT.InitThreadData();
                wti[0].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}, 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();
        }