/// <summary> /// Changes the current time - internal routine. /// Override it if you need time-dependent background color.. /// </summary> protected virtual void setTime(double newTime) { time = Arith.Clamp(newTime, Start, End); // Time-dependent scene? ITimeDependent intersectable = Intersectable as ITimeDependent; if (intersectable != null) { intersectable.Time = time; } // Time-dependent camera? ITimeDependent camera = Camera as ITimeDependent; if (camera != null) { camera.Time = time; } // Time-dependent light sources? foreach (ILightSource light in Sources) { ITimeDependent li = light as ITimeDependent; if (li != null) { li.Time = time; } } }
/// <summary> /// Clone all the time-dependent components, share the others. /// </summary> /// <returns></returns> public virtual object Clone() { AnimatedRayScene sc = new AnimatedRayScene(); ITimeDependent intersectable = Intersectable as ITimeDependent; sc.Intersectable = (intersectable == null) ? Intersectable : (IIntersectable)intersectable.Clone(); sc.BackgroundColor = (double[])BackgroundColor.Clone(); ITimeDependent camera = Camera as ITimeDependent; sc.Camera = (camera == null) ? Camera : (ICamera)camera.Clone(); ILightSource[] tmp = new ILightSource[Sources.Count]; Sources.CopyTo(tmp, 0); for (int i = 0; i < tmp.Length; i++) { ITimeDependent source = tmp[i] as ITimeDependent; if (source != null) { tmp[i] = (ILightSource)source.Clone(); } } sc.Sources = new LinkedList <ILightSource>(tmp); sc.Start = Start; sc.End = End; sc.setTime(Time); // propagates the current time to all time-dependent components.. return(sc); }
public WorkerThreadInit(IRenderer r, ITimeDependent sc, ITimeDependent imf, int wid, int hei) { scene = sc; imfunc = imf; rend = r; width = wid; height = hei; }
public void ShareCloneChildren(DefaultSceneNode n) { foreach (var child in children) { ITimeDependent cha = child as ITimeDependent; n.InsertChild((cha == null) ? child : (ISceneNode)cha.Clone(), child.ToParent); } }
/// <summary> /// Redraws the whole image. /// </summary> private void RenderImage() { Cursor.Current = Cursors.WaitCursor; EnableRendering(false); width = ImageWidth; if (width <= 0) { width = panel1.Width; } height = ImageHeight; if (height <= 0) { height = panel1.Height; } superSampling = (int)numericSupersampling.Value; outputImage = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); IRayScene scene = FormSupport.getScene(textParam.Text); // scene prototype IImageFunction imf = FormSupport.getImageFunction(scene); imf.Width = width; imf.Height = height; IRenderer rend = FormSupport.getRenderer(imf); rend.Width = width; rend.Height = height; rend.Adaptive = 0; rend.ProgressData = progress; progress.Continue = true; // animation: ITimeDependent sc = scene as ITimeDependent; if (sc != null) { sc.Time = (double)numTime.Value; } MT.InitThreadData(); Stopwatch sw = new Stopwatch(); sw.Start(); rend.RenderRectangle(outputImage, 0, 0, width, height); sw.Stop(); labelElapsed.Text = string.Format("Elapsed: {0:f1}s", 1.0e-3 * sw.ElapsedMilliseconds); pictureBox1.Image = outputImage; EnableRendering(true); Cursor.Current = Cursors.Default; }
public WorkerThreadInit(IRenderer r, ITimeDependent sc, ITimeDependent imf, Bitmap im, int wid, int hei, int threadNo, int threads) { scene = sc; imfunc = imf; rend = r; image = im; id = threadNo; width = wid; height = hei; sel = (n) => (n % threads) == threadNo; }
/// <summary> /// Clone all the time-dependent components, share the others. /// </summary> /// <returns></returns> public virtual object Clone() { ITimeDependent datatd = data as ITimeDependent; Animation c = new Animation(param, (datatd == null) ? data : datatd.Clone()); c.Start = Start; c.End = End; c.Time = Time; c.Width = width; c.Height = height; c.bg = bg; c.fg = fg; c.setSlant(slant); return(c); }
/// <summary> /// Redraws the whole image. /// </summary> private void RenderImage() { Cursor.Current = Cursors.WaitCursor; SetGui(false); width = ImageWidth; if (width <= 0) { width = panel1.Width; } height = ImageHeight; if (height <= 0) { height = panel1.Height; } superSampling = (int)numericSupersampling.Value; Bitmap im = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); MT.InitThreadData(); if (data == null) { data = FormSupport.getData(textParam.Text); // animation data } IImageFunction imf = FormSupport.getImageFunction(textParam.Text, data); imf.Width = width; imf.Height = height; IRenderer rend = FormSupport.getRenderer(textParam.Text, imf); rend.Width = width; rend.Height = height; rend.Adaptive = 0; rend.ProgressData = progress; progress.Continue = true; // animation: ITimeDependent imftd = imf as ITimeDependent; if (imftd != null) { imftd.Time = (double)numTime.Value; } Stopwatch sw = new Stopwatch(); sw.Start(); rend.RenderRectangle(im, 0, 0, width, height); sw.Stop(); labelElapsed.Text = string.Format(CultureInfo.InvariantCulture, "Elapsed: {0:f1}s", 1.0e-3 * sw.ElapsedMilliseconds); SetImage((Bitmap)im.Clone()); string fileName = Util.FileNameString(textParam.Text) + ".png"; im.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); im.Dispose(); SetGui(true); Cursor.Current = Cursors.Default; }
/// <summary> /// Worker thread (picks up individual frames and renders them one by one). /// </summary> protected void RenderWorker() { // thread-specific data: ITimeDependent datatd = data as ITimeDependent; object myData = (datatd == null) ? data : datatd.Clone(); MT.InitThreadData(); IImageFunction imf = FormSupport.getImageFunction(textParam.Text, myData); imf.Width = width; imf.Height = height; ITimeDependent imftd = imf as ITimeDependent; IRenderer rend = FormSupport.getRenderer(textParam.Text, imf); rend.Width = width; rend.Height = height; rend.Adaptive = 0; // turn off adaptive bitmap synthesis completely (interactive preview not needed) rend.ProgressData = progress; // worker loop: while (true) { double myTime; int myFrameNumber; lock ( progress ) { if (!progress.Continue || time > end) { sem.Release(); // chance for the main animation thread to give up as well.. return; } // got a frame to compute: myTime = time; time += dt; myFrameNumber = frameNumber++; } // set up the new result record: Result r = new Result(); r.image = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); r.frameNumber = myFrameNumber; // set specific time to my image function: if (imftd != null) { imftd.Time = myTime; } // render the whole frame: rend.RenderRectangle(r.image, 0, 0, width, height); // ... and put the result into the output queue: lock ( queue ) { queue.Enqueue(r); } sem.Release(); // notify the main animation thread } }
/// <summary> /// Worker thread (picks up individual frames and renders them one by one). /// </summary> protected void RenderWorker(object spec) { // thread-specific data: WorkerThreadInit init = spec as WorkerThreadInit; if (init == null) { return; } MT.InitThreadData(); // worker loop: while (true) { double myTime; double myEndTime; int myFrameNumber; lock ( progress ) { if (!progress.Continue || time > end) { sem.Release(); // chance for the main animation thread to give up as well.. return; } // got a frame to compute: myTime = time; myEndTime = (time += dt); myFrameNumber = frameNumber++; } // set up the new result record: Result r = new Result(); r.image = new Bitmap(init.width, init.height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); r.frameNumber = myFrameNumber; // set specific time to my scene: if (init.scene != null) { init.scene.Time = myTime; } ITimeDependent anim = init.rend as ITimeDependent; if (anim != null) { anim.Start = myTime; anim.End = myEndTime; } if (init.imfunc != null) { init.imfunc.Start = myTime; init.imfunc.End = myEndTime; } // render the whole frame: init.rend.RenderRectangle(r.image, 0, 0, init.width, init.height); // ... and put the result into the output queue: lock ( queue ) { queue.Enqueue(r); } sem.Release(); // notify the main animation thread } }
/// <summary> /// Redraws the whole image. /// </summary> private void RenderImage() { Cursor.Current = Cursors.WaitCursor; buttonRender.Enabled = false; buttonRenderAnim.Enabled = false; buttonRes.Enabled = false; width = ImageWidth; if (width <= 0) { width = panel1.Width; } height = ImageHeight; if (height <= 0) { height = panel1.Height; } superSampling = (int)numericSupersampling.Value; Bitmap newImage = new Bitmap(width, height, PixelFormat.Format24bppRgb); if (scene == null) { scene = FormSupport.getScene(); // scene prototype } IImageFunction imf = FormSupport.getImageFunction(scene); imf.Width = width; imf.Height = height; IRenderer rend = FormSupport.getRenderer(imf, superSampling); rend.Width = width; rend.Height = height; rend.Adaptive = 0; rend.ProgressData = progress; progress.Continue = true; // animation: ITimeDependent sc = scene as ITimeDependent; if (sc != null) { sc.Time = (double)numTime.Value; } MT.InitThreadData(); Stopwatch sw = new Stopwatch(); sw.Start(); rend.RenderRectangle(newImage, 0, 0, width, height); sw.Stop(); labelElapsed.Text = string.Format(CultureInfo.InvariantCulture, "Elapsed: {0:f1}s", 1.0e-3 * sw.ElapsedMilliseconds); setImage(ref outputImage, newImage); buttonRender.Enabled = true; buttonRenderAnim.Enabled = true; buttonRes.Enabled = true; Cursor.Current = Cursors.Default; }