X
7501 Rate this article:
No rating

Making movies with IDL, part II

Anonym

Last week, I gave an example of making a movie with IDLffVideoWrite and DG. This week, I’ll use NG to make a similar movie. The example is again written as a procedure. Start the program by declaring some test data and making a simple visualization:

pro ng_movie_ex
   compile_opt idl2

   data = dist(30)

   s = surface(data, color='blue', /buffer)
   c = contour(data, n_levels=10, zvalue=0.0, /overplot)
   t = text(0.5, 0.9, 'IDL Movie Example - NG', alignment=0.5, font_size=16)

Note that the BUFFER property is set on the call to SURFACE. It forces the visualization to be rendered to an offscreen buffer; it’s the analog to the DG Z buffer device. Next, set up the IDLffVideoWrite object:

   video_file = 'ng_movie_ex.mp4'
   video = idlffvideowrite(video_file)
   framerate = 10
   wdims = s.window.dimensions
   stream = video.addvideostream(wdims[0], wdims[1], framerate)

As in last week’s example, I’ve chosen to output to an MPEG-4 video file. The dimensions of the movie are taken from the dimensions of the buffer (the default, 640 x 512) created in the call to the SURFACE function. The next step is to make and load frames into the movie file:

   nframes = 50
   for i=0, nframes-1 do begin
      s.rotate, 1.0, /yaxis               ; degrees
      c.zvalue = i*max(s.zrange)/nframes  ; data coordinates
      timestamp = video.put(stream, s.copywindow())
   endfor

On each iteration of the loop:

  1. The Rotate method rotates the surface by one degree about the global y-axis of the visualization (this is from Object Graphics; +x is right, +y is up, +z is pointed toward you)
  2. By modifying its ZVALUE property, the contour plot moves up by a fraction of the total height of the surface.
  3. The CopyWindow method (the analog to the TVRD function in DG) takes a picture of the visualization in the buffer. The picture is a pixel-interleaved RGB image, with dimensions 3 x 640 x 512.
  4. The Put method of IDLffVideoWrite loads this picture as a frame into the video stream.

End the program by destroying the video object and the buffered graphic:

   video.cleanup
   print, 'File "' + video_file + '" written to current directory.'
   s.close
end

Click below to see the resulting video on the VIS YouTube channel. [youtube http://www.youtube.com/watch?v=ixGJIViukDA]   Notes:

  1. I have a more complex NG movie example that uses the SetData method introduced in 8.1. You can download it from this [exelisvis.com] page; look for the “What's New in IDL 8.1” webinar files, grab them and look for the program called VIDEO_WRITE1. I may give this example the blog treatment at a later point.
  2. I also have two other fun examples that should get the blog treatment: a) creating an AVI movie that can be embedded in a PowerPoint presentation, and b) creating a SWF movie that, with an HTML+Javascript framework, can be viewed in a web browser. Both are included in the IDL 8.1 examples above; look for the program VIDEO_WRITE2 and its output.