/// <summary> /// Redraws the whole image. /// </summary> private void redraw() { 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, System.Drawing.Imaging.PixelFormat.Format24bppRgb); if (imf == null) { imf = FormSupport.getImageFunction(out scene, brepScene); } imf.Width = width; imf.Height = height; if (rend == null) { rend = FormSupport.getRenderer(imf); } rend.Width = width; rend.Height = height; CSGInnerNode.ResetStatistics(); MT.InitThreadData(); Stopwatch sw = new Stopwatch(); sw.Start(); rend.RenderRectangle(newImage, 0, 0, width, height); sw.Stop(); labelElapsed.Text = string.Format(CultureInfo.InvariantCulture, "{0:f1}s [ {1}x{2}, r{3:#,#}k, i{4:#,#}k, bb{5:#,#}k, t{6:#,#}k ]", 1.0e-3 * sw.ElapsedMilliseconds, width, height, (Intersection.countRays + 500L) / 1000L, (Intersection.countIntersections + 500L) / 1000L, (CSGInnerNode.countBoundingBoxes + 500L) / 1000L, (CSGInnerNode.countTriangles + 500L) / 1000L); setImage(ref outputImage, newImage); Cursor.Current = Cursors.Default; }
/// <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; if (rend == null) { rend = FormSupport.getRenderer(imf); } rend.Width = width; rend.Height = height; rend.Adaptive = 8; rend.ProgressData = progress; progress.SyncInterval = 5000L; progress.Reset(); CSGInnerNode.ResetStatistics(); MT.InitThreadData(); lock ( sw ) { sw.Reset(); sw.Start(); } 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}, r{3:#,#}k, i{4:#,#}k, bb{5:#,#}k, t{6:#,#}k ]", 1.0e-3 * elapsed, width, height, (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(); }
/// <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(); }
/// <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 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)) ? 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(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(); }