void renderWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; RenderUIArgs renderUIArgs = (RenderUIArgs)e.Argument; // TODO: Params from UI int volume_width = 640; int volume_height = 480; int volume_depth = _volumeDepth; int image_width = renderPictureBox.Size.Width; int image_height = renderPictureBox.Size.Height; render = new Render(volume_width, volume_height, volume_depth, image_width, image_height); Bitmap bitmap = new Bitmap(image_width, image_height, PixelFormat.Format32bppArgb); byte[] volume = new byte[volume_width * volume_height * volume_depth]; int[] image = new int[image_width * image_height]; float density = 0.08f, brightness = 5.0f, transoffset = 0.0f, transscale = 1.0f; bool linearfilter = true ; float rotx = 0.0f, roty = 0.0f, rotz = 0.0f, transx = 0.0f, transy = 0.0f, transz = 4.0f; int offset = 0; uint imageNumber = 0; bool isRenderTime = false; #if RENDER_LOG TextWriter tw = new StreamWriter("data.txt"); #endif while (!worker.CancellationPending) { ImageData imdata; if (!imageDataQueue.TryDequeue(out imdata)) { continue; } if (imdata.deltaVoltage > _thresholdDeltaVoltage) { Buffer.BlockCopy(imdata.imageArray, 0, volume, offset, imdata.imageArray.Length); offset += imdata.imageArray.Length; imageNumber++; worker.ReportProgress(0, new RenderUIUpdateArgs(imageNumber)); } else { if (imageNumber != 0) { isRenderTime = true; } } #if RENDER_LOG tw.WriteLine("queue count: {0}", imageDataQueue.Count); tw.WriteLine("deltaV: {0}", imdata.deltaVoltage); tw.WriteLine("imnumber: {0}", imageNumber); tw.WriteLine("isrendertime: {0}", isRenderTime); #endif if (isRenderTime) { #if RENDER_LOG long render_start = DateTime.Now.Ticks; tw.WriteLine("render start {0}", render_start); #endif try { rotx = Convert.ToSingle(renderUIArgs.rotxTextBox.Text); roty = Convert.ToSingle(renderUIArgs.rotyTextBox.Text); rotz = Convert.ToSingle(renderUIArgs.rotzTextBox.Text); transx = Convert.ToSingle(renderUIArgs.transxTextBox.Text); transy = Convert.ToSingle(renderUIArgs.transyTextBox.Text); transz = Convert.ToSingle(renderUIArgs.transzTextBox.Text); density = Convert.ToSingle(renderUIArgs.densityTextBox.Text); brightness = Convert.ToSingle(renderUIArgs.brightnessTextBox.Text); transoffset = Convert.ToSingle(renderUIArgs.transoffsetTextBox.Text); transscale = Convert.ToSingle(renderUIArgs.transscaleTextBox.Text); linearfilter = renderUIArgs.linfilterCheckBox.Checked; render.SetParams(density, brightness, transoffset, transscale, linearfilter); render.SetViewMatrix(rotx, roty, rotz, transx, transy, transz); render.Update(ref volume, ref image); for (int x = 0, idx = 0; x < image_width; x++) { for (int y = 0; y < image_height; y++, idx++) { bitmap.SetPixel(x, y, Color.FromArgb(image[idx])); } } renderPictureBox.Image = (Image)bitmap; } catch (FormatException) { } offset = 0; imageNumber = 0; isRenderTime = false; #if RENDER_LOG tw.WriteLine("render time: {0} ms", TimeSpan.FromTicks(DateTime.Now.Ticks - render_start).TotalMilliseconds); #endif } } #if RENDER_LOG tw.Close(); #endif }