Example #1
0
        private void buttonRender_Click(object sender, EventArgs e)
        {
            if (collectDataCheckBox.Checked)
            {
                additionalViews.SetNewDimensions(ImageWidth, ImageHeight);
                additionalViews.NewRenderInitialization();
            }
            else if (!additionalViews.mapsEmpty)
            {
                additionalViews.form?.ExportDataButtonsEnabled(true);
            }

            if (aThread != null)
            {
                return;
            }

            // GUI stuff:
            SetGUI(false);

            additionalViews.form?.RenderButtonsEnabled(false);
            MT.renderingInProgress = true;
            Statistics.Reset();

            lock (progress)
                progress.Continue = true;

            SetText("Wait a moment..");
            aThread = new Thread(new ThreadStart(RenderImage));
            aThread.Start();
        }
Example #2
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();
        }
Example #3
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();
        }