manpagez: man pages & more
info mathgl
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.2 Drawing to file

Another way of using MathGL library is the direct picture writing to file. It is most usable for plot creating during calculation or for using of small programs (like Matlab or Scilab scripts) for visualizing repetitive sets of data. But the speed of drawing is much higher in comparison with a script language. There are two classes for exporting in file: class mglGraphZB saves in bitmap format (like PNG), mglGraphPS saves in vector PostScript format (see section Plotter classes).

The following code produces a bitmap PNG picture:

    int main(int ,char **)
    {
        mglGraphZB gr;
        gr.Alpha(true);
        gr.Light(true);             gr.Light(0,mglPoint(1,0,-1));
        sample(&gr,NULL);           // The same drawing function.
        gr.WritePNG("test.png");    // Don't forget to save the result!
        return 0;
    }

The only difference from the previous (using windows) variant is manual switching the transparency Alpha and lightning Light on, if the plot requires it. The using of frames is not advisable since the whole image is prepared each time. If function sample contains frames then each frame will be saved to a separate file. In principle, one does not need to separate drawing functions in case of direct file writing in consequence of the single calling of this function for each picture. However, one may use the same drawing procedure to create a plot with changed parameters, to export in different file types, to emphasize the drawing code and so on. So, in future I will put the drawing in separate function.

The code for export in vector EPS file looks the same:

    int main(int ,char **)
    {
        mglGraphPS gr;
        gr.Light(true);             gr.Light(0,mglPoint(1,0,-1));
        sample(&gr,NULL);           // The same drawing function.
        gr.WriteEPS("test.eps");    // Don't forget to save the result!
        return 0;
    }

The differences from the using of bitmap picture are: applying of the other class mglGraphPS, and writing to other format (function WriteEPS() instead of function WritePNG()). Moreover, there is no switching of the plot transparency Alpha since EPS format does not support it. Possibly I shall include transparency in future by program emulation.

Classes mglGraphZB and mglGraphPS have some merits and demerits. Class mglGraphZB draws beautiful surface with transparency, smoothed colors and lightning, but the output picture is bitmap, that leads to a bad scalability. On the contrary, class mglGraphPS creates vector file with excellent scalability. But file has large size (especially for surfaces), it does not support transparency and color smoothing. So, vector picture looks stylish but a bit angularly.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.