9. Printing, Exporting, and Making Videos

In order to include the post-processed results in a report or in a presentation, it is necessary to export the Scene display to a file, which then can be included in a document. baspl++ supports

  • Printing directly to a printer or exporting to a file.

  • Printing can be done from the GUI only, while exporting to a file can be done from the GUI and from the command-line. The latter is particularly interesting, as it can be used within scripts.

  • For printing, bitmap and vector rendering is supported. Default is bitmap rendering. baspl++ obtains the list of available printers and automatically selects the corresponding number of pixels per inch. Thus, bitmap rendering is very accurate.

  • Screen shots can be exported to any of the well-known pixel-based formats such as PNG and JPEG. In addition, the PostScript (ps), Encapsulated PostScript (eps), Scalable Vector Graphics (svg), and Portable Document Format (pdf) format are supported as vector formats.

  • Movie files can be generated with baspl++, and then included in on-line presentations. The supported file formats depend on the software that is installed. By default, only the flc file format is supported. It is a lossless format but supports only 256 colours. On non-UNIX machines, Apple's QuickTime video player may be necessary to display these movie files.

9.1. Exporting to Pixel-based Formats

Pixel- or bitmap-based output always exactly corresponds to what is displayed on-screen, since OpenGL has a mechanism to extract the displayed pixels. The downside is that the output is not scalable. However, sufficiently large images still allow for excellent quality, even in large prints.

  1. Decide which file format to use. baspl++ can export to many different file formats. The recommended pixel-based format however is the Portable Network Graphics (PNG) format. It supports lossless compression and a high number of colours. Furthermore it can be read by most other applications such as web browsers and image viewing and processing software. Many other formats, such as JPEG are not lossless (thus image quality is impaired).

  2. To export from the command-line, type

    s.export_to_file('my_image.png')

    The size of the image is by default derived from that of the Scene window. Thus, if the Scene window has a size of 400 x 400 pixel, the image will have that resolution. If a different size is needed, the size parameter can be specified:

    s.export_to_file('my_image.png', pixel_size=(800, 600))

    This will create an image of size 800 x 600, irrespective of the Scene window size. The maximum size can be very large: When necessary, baspl++ performs a technique called "tiling" which consists of making several screen shots of portions of the image and then combining the portions to a single image.

9.2. Exporting to PostScript

PostScript and Encapsulated PostScript documents are vector-based and device-independent, thus - contrary to pixel-based formats - one can theoretically achieve optimum quality for any resolution. A wide range of scalable high-quality fonts can be used to typeset text. This makes this format attractive for inclusion in reports, where printing quality is a concern. Also, PostScript documents can be converted to Portable Document Format (PDF), a format that can be viewed and printed in high quality on almost every machine.

baspl++ makes use of an open-source library called gl2ps to convert OpenGL commands to PostScript directives. This is the best way to ensure that the printed output corresponds to what is displayed with OpenGL.

However, due to the different nature of OpenGL and PostScript technologies, there is a number of incompatibilities that must be considered:

  • OpenGL does not directly support vector fonts like TrueType- or PostScript fonts. In order to produce high-quality text, baspl++ tries to convert the pixel-font used in OpenGL into an equally-sized PostScript font.

  • Since OpenGL is for 3D display and PostScript is 2D, there must be a way of projecting polygons and other OpenGL primitives to 2D, much like this is done for on-screen display. OpenGL supports an output mode where exactly this is done, yielding primitives in 2D coordinates. For large problems, the number of polygons becomes huge, thus the PostScript document would become very large. The gl2ps library contains an algorithm to eliminate those polygons that are completely hidden by other polygons and thus are invisible. This elimination algorithm reduces the size of the PostScript document considerably.

  • Texturing is a crucial feature of OpenGL, enabling a much better colour interpolation between vertices than ordinary interpolation. Unfortunately, PostScript does not have anything equivalent to textures; thus a textured line or polygon needs to be split up into smaller primitives. The gl2ps library does not feature such an algorithm at the time, thus textured polygons and lines are not included at all in the PostScript document. The consequence is textures are temporarily disabled while the PostScript document is created.

To export to a file from the command-line, type

s.export_to_file('toto.ps')

The file format is determined from the file name extension. There are optional parameters to the export_to_file function, but they are normally not important.

9.3. Making a Movie File

To visualise dynamic behaviour, animations are very important. To include them in presentations, it is sometimes preferable to make a movie file instead of starting baspl++.

  1. Decide which file format to use. Three different file formats can be chosen from, of which we can recommend only one:

    • FLC: This is the recommended format, as it can be generated on every platform, preserves pixel quality and compresses colours only. FLC movies can be viewed with the xanim, the totem, the xine, or the mplayer tool. On some platforms, the integrated QuickTime video codec is able to display also FLC movies. On some platforms QuickTime must be installed in order to view FLC movies.

    • MPEG: Not recommended since the quality is (due to the lossy compression) not good enough, and is supported only when baspl++ is compiled with the gcc compiler. You must have the ffmpeg package installed.

    • AVI: The creation of movies in the AVI format is possible only when the ffmpeg package is installed.

  2. Set the size of the Scene window.

  3. The movie can be created either with the GUI or from the command-line (and thus by a script):

    • To create a movie file from the command-line, first create an object of class VideoRecorder:

      vs = VideoRecorder(s, 'my_movie.flc')

      Mandatory parameters are a reference to the Scene object from which the frames will be taken and the movie file name with the proper extension. The size of the movie frames is determined from the Scene object.

      Each time a new frame should be added, call

      vs.add_frame()

      When all frames have been added,

      vs.close()

      saves all frames in the movie file specified.

    • To create a movie file from the GUI, proceed like when printing or exporting from the GUI, but select the FLC format as output. When you click the button "print", the movie dialog appears

      • To add a frame manually to the video stream, click on the "add" button.

      • When all frames have been added click "ok".

      • To add frames automatically every fraction of a second, first choose the frame rate, then click "Record". The frames will be added now. When enough frames have been recorded, click "Finalize" (or "Cancel").

      • To clear previously added frames, click "Clear".

      Once the "Finalize" button has been pressed and the dialog has disappeared, the movie file has been created.

  4. To view the created movie, use a program like xanim, xine or MPlayer.