[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5 Export picture

Functions in this group save or give access to produced picture. So, usually they should be called after plotting is done.

MGL command: setsize w h
Method on mglGraph: void SetSize (int width, int height)
C function: void mgl_set_size (HMGL gr, int width, int height)

Sets size of picture in pixels. This function must be called before any other plotting because it completely remove picture contents.

MGL command: quality [val=2]
Method on mglGraph: void SetQuality (int val=MGL_DRAW_NORM)
C function: void mgl_set_quality (HMGL gr, int val)

Sets quality of the plot depending on value val: MGL_DRAW_WIRE=0 – no face drawing (fastest), MGL_DRAW_FAST=1 – no color interpolation (fast), MGL_DRAW_NORM=2 – high quality (normal), MGL_DRAW_HIGH=3 – high quality with 3d primitives (arrows and marks). If MGL_DRAW_LMEM=0x4 is set then direct bitmap drawing is used (low memory usage).

Method on mglGraph: int GetQuality ()
C function: int mgl_get_quality (HMGL gr)

Gets quality of the plot: MGL_DRAW_WIRE=0 – no face drawing (fastest), MGL_DRAW_FAST=1 – no color interpolation (fast), MGL_DRAW_NORM=2 – high quality (normal), MGL_DRAW_HIGH=3 – high quality with 3d primitives (arrows and marks). If MGL_DRAW_LMEM=0x4 is set then direct bitmap drawing is used (low memory usage).

Method on mglGraph: void StartGroup (const char *name)
C function: void mgl_start_group (HMGL gr, const char *name)

Starts group definition. Groups contain objects and other groups, they are used to select a part of a model to zoom to or to make invizible or to make semitransparent and so on.

Method on mglGraph: void EndGroup ()
C function: void mgl_end_group (HMGL gr)

Ends group definition.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.1 Export to file

These functions export current view to a graphic file. The filename fname should have appropriate extension. Parameter descr gives the short description of the picture. Just now the transparency is supported in PNG, SVG, OBJ and PRC files.

MGL command: write ['fname'='']
Method on mglGraph: void WriteFrame (const char *fname="", const char *descr="")
C function: void mgl_write_frame (HMGL gr, const char *fname, const char *descr)

Exports current frame to a file fname which type is determined by the extension. Parameter descr adds description to file (can be ""). If fname="" then the file ‘frame####.jpg’ is used, where ‘####’ is current frame id and name ‘frame’ is defined by plotid class property.

Method on mglGraph: void WritePNG (const char *fname, const char *descr="", int compr="", bool alpha=true)
C function: void mgl_write_png (HMGL gr, const char *fname, const char *descr)
C function: void mgl_write_png_solid (HMGL gr, const char *fname, const char *descr)

Exports current frame to PNG file. Parameter fname specifies the file name, descr adds description to file, alpha gives the transparency type. By default there are no description added and semitransparent image used. This function does nothing if HAVE_PNG isn’t defined during compilation of MathGL library.

Method on mglGraph: void WriteJPEG (const char *fname, const char *descr="")
C function: void mgl_write_jpg (HMGL gr, const char *fname, const char *descr)

Exports current frame to JPEG file. Parameter fname specifies the file name, descr adds description to file. By default there is no description added. This function does nothing if HAVE_JPEG isn’t defined during compilation of MathGL library.

Method on mglGraph: void WriteGIF (const char *fname, const char *descr="")
C function: void mgl_write_gif (HMGL gr, const char *fname, const char *descr)

Exports current frame to GIF file. Parameter fname specifies the file name, descr adds description to file. By default there is no description added. This function does nothing if HAVE_GIF isn’t defined during compilation of MathGL library.

Method on mglGraph: void WriteBMP (const char *fname, const char *descr="")
C function: void mgl_write_bmp (HMGL gr, const char *fname, const char *descr)

Exports current frame to BMP file. Parameter fname specifies the file name, descr adds description to file. There is no compression used.

Method on mglGraph: void WriteTGA (const char *fname, const char *descr="")
C function: void mgl_write_tga (HMGL gr, const char *fname, const char *descr)

Exports current frame to TGA file. Parameter fname specifies the file name, descr adds description to file. There is no compression used.

Method on mglGraph: void WriteEPS (const char *fname, const char *descr="")
C function: void mgl_write_eps (HMGL gr, const char *fname, const char *descr)

Exports current frame to EPS file using vector representation. So it is not recommended for the export of large data plot. It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter fname specifies the file name, descr adds description to file. By default there is no description added. If file name is terminated by ‘z’ (for example, ‘fname.eps.gz’) then file will be compressed in gzip format.

Method on mglGraph: void WriteBPS (const char *fname, const char *descr="")
C function: void mgl_write_eps (HMGL gr, const char *fname, const char *descr)

Exports current frame to EPS file using bitmap representation. Parameter fname specifies the file name, descr adds description to file. By default there is no description added. If file name is terminated by ‘z’ (for example, ‘fname.eps.gz’) then file will be compressed in gzip format.

Method on mglGraph: void WriteSVG (const char *fname, const char *descr="")
C function: void mgl_write_svg (HMGL gr, const char *fname, const char *descr)

Exports current frame to SVG (Scalable Vector Graphics) file using vector representation. In difference of EPS format, SVG format support transparency that allows to correctly draw semitransparent plot (like surfa, surf3a or cloud). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter fname specifies the file name, descr adds description to file (default is file name). If file name is terminated by ‘z’ (for example, ‘fname.svgz’) then file will be compressed in gzip format.

Method on mglGraph: void WriteTEX (const char *fname, const char *descr="")
C function: void mgl_write_tex (HMGL gr, const char *fname, const char *descr)

Exports current frame to LaTeX (package Tikz/PGF) file using vector representation. Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter fname specifies the file name, descr adds description to file (default is file name). Note, there is no text scaling now (for example, in subplots), what may produce miss-aligned labels.

Method on mglGraph: void WritePRC (const char *fname, const char *descr="", bool make_pdf=true)
C function: void mgl_write_prc (HMGL gr, const char *fname, const char *descr, int make_pdf)

Exports current frame to PRC file using vector representation (see http://en.wikipedia.org/wiki/PRC_%28file_format%29). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter fname specifies the file name, descr adds description to file (default is file name). If parameter make_pdf=true and PDF was enabled at MathGL configure then corresponding PDF file with 3D image will be created.

Method on mglGraph: void WriteOBJ (const char *fname, const char *descr="")
C function: void mgl_write_obj (HMGL gr, const char *fname, const char *descr)

Exports current frame to OBJ/MTL file using vector representation (see OBJ format for details). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter fname specifies the file name, descr adds description to file (default is file name).

Method on mglGraph: void WriteXYZ (const char *fname, const char *descr="")
C function: void mgl_write_xyz (HMGL gr, const char *fname, const char *descr)

Exports current frame to XYZ/XYZL/XYZF files using vector representation (see XYZ format for details). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter fname specifies the file name, descr adds description to file (default is file name).

Method on mglGraph: void WriteSTL (const char *fname, const char *descr="")
C function: void mgl_write_stl (HMGL gr, const char *fname, const char *descr)

Exports current frame to STL file using vector representation (see STL format for details). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter fname specifies the file name, descr adds description to file (default is file name.

Method on mglGraph: void WriteOFF (const char *fname, const char *descr="", bool colored=false)
C function: void mgl_write_off (HMGL gr, const char *fname, const char *descr, bool colored)

Exports current frame to OFF file using vector representation (see OFF format for details). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter fname specifies the file name, descr adds description to file (default is file name).

Method on mglGraph: void ShowImage (const char *viewer, bool nowait=false)
C function: void mgl_show_image (const char *viewer, int nowait)

Displays the current picture using external program viewer for viewing. The function save the picture to temporary file and call viewer to display it. If nowait=true then the function return immediately (it will not wait while window will be closed).

Method on mglGraph: void WriteJSON (const char *fname, const char *descr="")
C function: void mgl_write_json (HMGL gr, const char *fname, const char *descr)

Exports current frame to textual file using JSON format. Later this file can be used for faster loading and viewing by JavaScript script. Parameter fname specifies the file name, descr adds description to file.

Method on mglGraph: void ExportMGLD (const char *fname, const char *descr="")
C function: void mgl_export_mgld (HMGL gr, const char *fname, const char *descr)

Exports points and primitives in file using MGLD format. Later this file can be used for faster loading and viewing by mglview utility. Parameter fname specifies the file name, descr adds description to file (default is file name).

Method on mglGraph: void ImportMGLD (const char *fname, bool add=false)
C function: void mgl_import_mgld (HMGL gr, const char *fname, int add)

Imports points and primitives in file using MGLD format. Later this file can be used for faster loading and viewing by mglview utility. Parameter fname specifies the file name, add sets to append or replace primitives to existed ones.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.2 Frames/Animation

These functions provide ability to create several pictures simultaneously. For most of cases it is useless but for widget classes (see Widget classes) they can provide a way to show animation. Also you can write several frames into animated GIF file.

Method on mglGraph: void NewFrame ()
C function: void mgl_new_frame (HMGL gr)

Creates new frame. Function returns current frame id. This is not thread safe function in OpenGL mode! Use direct list creation in multi-threading drawing. The function EndFrame() must be call after the finishing of the frame drawing for each call of this function.

Method on mglGraph: void EndFrame ()
C function: void mgl_end_frame (HMGL gr)

Finishes the frame drawing.

Method on mglGraph: int GetNumFrame ()
C function: int mgl_get_num_frame (HMGL gr)

Gets the number of created frames.

Method on mglGraph: void SetFrame (int i)
C function: void mgl_set_frame (HMGL gr, int i)

Finishes the frame drawing and sets drawing data to frame i, which should be in range [0, GetNumFrame()-1]. This function is similar to EndFrame() but don’t add frame to the GIF image.

Method on mglGraph: void GetFrame (int i)
C function: void mgl_get_frame (HMGL gr, int i)

Replaces drawing data by one from frame i. Function work if MGL_VECT_FRAME is set on (by default).

Method on mglGraph: void ShowFrame (int i)
C function: void mgl_show_frame (HMGL gr, int i)

Appends drawing data from frame i to current one. Function work if MGL_VECT_FRAME is set on (by default).

Method on mglGraph: void DelFrame (int i)
C function: void mgl_del_frame (HMGL gr, int i)

Deletes drawing data for frame i and shift all later frame indexes. Function work if MGL_VECT_FRAME is set on (by default). Do nothing in OpenGL mode.

Method on mglGraph: void ResetFrames ()
C function: void mgl_reset_frames (HMGL gr)

Reset frames counter (start it from zero).

Method on mglGraph: void StartGIF (const char *fname, int ms=100)
C function: void mgl_start_gif (HMGL gr, const char *fname, int ms)

Start writing frames into animated GIF file fname. Parameter ms set the delay between frames in milliseconds. You should not change the picture size during writing the cinema. Use CloseGIF() to finalize writing. Note, that this function is disabled in OpenGL mode.

Method on mglGraph: void CloseGIF ()
C function: void mgl_close_gif (HMGL gr)

Finish writing animated GIF and close connected pointers.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.3 Bitmap in memory

These functions return the created picture (bitmap), its width and height. You may display it by yourself in any graphical library (see also, Widget classes) or save in file (see also, Export to file).

Method on mglGraph: const unsigned char * GetRGB ()
Method on mglGraph: void GetRGB (char *buf, int size)
Method on mglGraph: void GetBGRN (char *buf, int size)
C function: const unsigned char * mgl_get_rgb (HMGL gr)

Gets RGB bitmap of the current state of the image. Format of each element of bits is: {red, green, blue}. Number of elements is Width*Height. Position of element {i,j} is [3*i + 3*Width*j] (or is [4*i + 4*Width*j] for GetBGRN()). You have to provide the proper size of the buffer, buf, i.e. the code for Python should look like

from mathgl import *
gr = mglGraph();
bits='\t';
bits=bits.expandtabs(4*gr.GetWidth()*gr.GetHeight());
gr.GetBGRN(bits, len(bits));
Method on mglGraph: const unsigned char * GetRGBA ()
Method on mglGraph: void GetRGBA (char *buf, int size)
C function: const unsigned char * mgl_get_rgba (HMGL gr)

Gets RGBA bitmap of the current state of the image. Format of each element of bits is: {red, green, blue, alpha}. Number of elements is Width*Height. Position of element {i,j} is [4*i + 4*Width*j].

Method on mglGraph: int GetWidth ()
Method on mglGraph: int GetHeight ()
C function: int mgl_get_width (HMGL gr)
C function: int mgl_get_height (HMGL gr)

Gets width and height of the image.

Method on mglGraph: mglPoint CalcXYZ (int xs, int ys)
C function: void mgl_calc_xyz (HMGL gr, int xs, int ys, mreal *x, mreal *y, mreal *z)

Calculate 3D coordinate {x,y,z} for screen point {xs,ys}. At this moment it ignore perspective and transformation formulas (curvilinear coordinates). The calculation are done for the last used InPlot (see Subplots and rotation).

Method on mglGraph: mglPoint CalcScr (mglPoint p)
C function: void mgl_calc_scr (HMGL gr, mreal x, mreal y, mreal z, int *xs, int *ys)

Calculate screen point {xs,ys} for 3D coordinate {x,y,z}. The calculation are done for the last used InPlot (see Subplots and rotation).

Method on mglGraph: void SetObjId (int id)
C function: void mgl_set_obj_id (HMGL gr, int id)

Set the numeric id for object or subplot/inplot.

Method on mglGraph: int GetObjId (int xs, int ys)
C function: int mgl_get_obj_id (HMGL gr, int xs, int ys)

Get the numeric id for most upper object at pixel {xs, ys} of the picture.

Method on mglGraph: int GetSplId (int xs, int ys)
C function: int mgl_get_spl_id (HMGL gr, int xs, int ys)

Get the numeric id for most subplot/inplot at pixel {xs, ys} of the picture.

Method on mglGraph: void Highlight (int id)
C function: void mgl_highlight (HMGL gr, int id)

Highlight the object with given id.

Method on mglGraph: long IsActive (int xs, int ys, int d=1)
C function: long mgl_is_active (HMGL gr, int xs, int ys, int d)

Checks if point {xs, ys} is close to one of active point (i.e. mglBase::Act) with accuracy d and return its index or -1 if not found. Active points are special points which characterize primitives (like edges and so on). This function for advanced users only.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.4 Parallelization

Many of things MathGL do in parallel by default (if MathGL was built with pthread). However, there is function which set the number of threads to be used.

C function: int mgl_set_num_thr (int n)

Set the number of threads to be used by MathGL. If n<1 then the number of threads is set as maximal number of processors (cores). If n=1 then single thread will be used (this is default if pthread was disabled).

Another option is combining bitmap image (taking into account Z-ordering) from different instances of mglGraph. This method is most appropriate for computer clusters when the data size is so large that it exceed the memory of single computer node.

Method on mglGraph: int Combine (const mglGraph *g)
C function: int mgl_combine_gr (HMGL gr, HMGL g)

Combine drawing from instance g with gr (or with this) taking into account Z-ordering of pixels. The width and height of both instances must be the same.

Method on mglGraph: int MPI_Send (int id)
C function: int mgl_mpi_send (HMGL gr, int id)

Send graphical information from node id using MPI. The width and height in both nodes must be the same.

Method on mglGraph: int MPI_Recv (int id)
C function: int mgl_mpi_send (HMGL gr, int id)

Receive graphical information from node id using MPI. The width and height in both nodes must be the same.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Dimitrios Eftaxiopoulos on August 18, 2013 using texi2html 1.82.