Beispiel #1
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();
        }
Beispiel #2
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();
        }