[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The class mglGraph (see section MathGL core) provide the basic tools for creating scientific graphics but it is abstract class. The matter is that there are several possible way to draw a graphics: in bitmap, in vector file, using OpenGL and so on. As result, user should use some of derived classes to do actual drawing. In principle, it is possible to derive a class exactly from mglGraph (and it was in v.1.6). But I recommend to derive from mglGraphAB class for higher compatibility of produced graphics from different classes. Class mglGraphAB is another abstract class which provide basic coordinates transformation, plotting functions and export to bitmap picture. It still require a functions for drawing lines, triangles and quadrangles. So below a set of “plotter” classes with short comments.
Abstract class mglGraphAB implements plotting function for 1D, 2D and 3D plots using Z-ordering and provides base functionality for to screen coordinate transformation, bitmap creation and so on. Class is defined in #include <mgl/mgl_ab.h>
.
Class mglGraphZB implements plotting function for 1D, 2D and 3D plots using Z-Buffer. It is useful for off-screen (for console or SSH terminal) programs. Also this class can be used in any other programs which may draw bitmap on the screen (for example, by using FLTK, Qt, wxWidgets libraries and so on). Note that bitmap picture is saved while exporting to EPS format. The produced graphics have better quality but slower in comparison with graphics in the class mglGraphPS. Class is defined in #include <mgl/mgl_zb.h>
.
Class mglGraphPS implements plotting functions for 1D, 2D and 3D plots and exports them to PostScript or SVG file. It is useful for off-screen (for console or SSH terminal) programs. Note that there is no transparency support now and color interpolation and lightning support is limited (not so nice as in class mglGraphZB). As result the plots with transparency (SurfA, Surf3A, CloudP, CloudQ) may look not so good. However the speed of drawing is higher in comparison with one in the class mglGraphZB. Class is defined in #include <mgl/mgl_eps.h>
.
Class mglGraphGL implements plotting function for 1D, 2D and 3D plots under OpenGL. This class can not be used in off-screen applications. Note, that several transparent overlapped surfaces are drawn not so correctly due to OpenGL limitations. Class is defined in #include <mgl/mgl_gl.h>
.
Class mglGraphIDTF implements plotting function for 1D, 2D and 3D plots and export it in IDTF format. Later this file can be converted in U3D format. Class is defined in #include <mgl/mgl_idtf.h>
.
4.1 mglGraphAB class |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
#cindex mglDraw
Generally this class is a bit less abstract class than mglGraph class (see section MathGL core). It provide many protected methods for handling intermediate data from mglGraph methods and require a few methods to be defined by derived class. The developers of derived classes should look on file ‘mgl_ab.h’ and comments inside it or contact me.
Here I just show main public methods for class mglGraphAB. There are functions returning 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).
mglGraphAB
(C++): const unsigned char *
GetBits ()mglGraph
(Python): void
GetRGB (char *
buf, int
size)mglGraph
(Python): void
GetBGRN (char *
buf, int
size)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()
). For Python you have to provide the proper size of the buffer, buf i.e. the code should look like
from mathgl import * gr = mglGraph(); bits='\t'; bits=bits.expandtabs(4*gr.GetWidth()*gr.GetHeight()); gr.GetBGRN(bits, len(bits));
mglGraphAB
(C++): const unsigned char *
GetRGBA ()mglGraph
(Python): void
GetRGBA (char *
buf, int
size)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].
mglGraphAB
(C++, Python): int
GetWidth ()mglGraphAB
(C++, Python): int
GetHeight ()int
mgl_get_width (HMGL
gr)int
mgl_get_height (HMGL
gr)Gets width and height of the image.
Class mglGraphAB is the base class for “widget classes”. So there are set of functions for handling window behavior. Most of them are applicable only for “window” classes (like mglGraphFLTK and so on, see section Widget classes). In all other classes these functions just do nothing. You should provide the corresponding interface in derived “widget” classes for user convenience.
void
Window (int
argc, char **
argv, int (*
draw)(mglGraph *
gr, void *
p), const char *
title, void *
par=NULL
, void (*
reload)(int
next, void *
p)=NULL
, bool
maximize=false
)This function creates a window for plotting. Parameters argc, argv contain OS specific information and should be the same as in function main(int argc,char **argv)
. Parameter draw sets a pointer (this is the name of function) to drawing function. There is support of a list of plots (frames). So as one can prepare a set of frames at first and redraw it fast later (but it requires more memory). Function should return positive number of frames for the list or zero if it will plot directly. Note, that draw can be NULL
for displaying static bitmaps only (no animation or slides). Parameter title sets the title of the window. Parameter par contains pointer to data for the plotting function draw. Parameter maximize=true
open maximized window.
There are some keys handles for manipulating by the plot: ’a’, ’d’, ’w’, ’s’ for the rotating; ’,’, ’.’ for viewing of the previous or next frames in the list; ’r’ for the switching of transparency; ’f’ for the switching of lightning; ’x’ for hiding (closing) the window.
IMPORTANT!!! You need to add a call of Rotate() (see section Transformation matrix) function for having possibility of plot rotation. If plot should be unrotated by default just add Rotate(0,0)
in drawing function.
void
Window (int
argc, char **
argv, mglDraw *
draw, const char *
title, bool
maximize=false
)This function is mostly the same as previous one. The only difference is that the drawing function and function for data reloading are specified as methods on a class inherited from class mglDraw
. This class is defined in #include <mgl/mgl_define.h>
and have only 2 methods:
class mglDraw { public: virtual int Draw(mglGraph *) { return 0; }; virtual void Reload(int) {}; };
You should inherit yours class from mglDraw
and reimplement one or both functions for using this function.
mglGraphAB
(C++): void
ToggleAlpha ()int
mgl_wnd_toggle_alpha (HMGL
gr)Switch on/off transparency but do not overwrite switches in user drawing function.
mglGraphAB
(C++): void
ToggleLight ()int
mgl_wnd_toggle_light (HMGL
gr)Switch on/off lighting but do not overwrite switches in user drawing function.
mglGraphAB
(C++): void
ToggleZoom ()int
mgl_wnd_toggle_zoom (HMGL
gr)Switch on/off zooming by mouse as region selection.
mglGraphAB
(C++): void
ToggleRotate ()int
mgl_wnd_toggle_rotate (HMGL
gr)Switch on/off rotation by mouse. Usually, left button is used for rotation, middle button for shift, right button for zoom/perspective.
mglGraphAB
(C++): void
ToggleNo ()int
mgl_wnd_toggle_no (HMGL
gr)Switch off all zooming and rotation and restore initial state.
mglGraphAB
(C++): void
Update ()int
mgl_wnd_update (HMGL
gr)Update window contents.
mglGraphAB
(C++): void
ReLoad (bool
o)int
mgl_wnd_reload (HMGL
gr, int
val)Reload user data and update picture.
mglGraphAB
(C++): void
Adjust ()int
mgl_wnd_adjust (HMGL
gr)Adjust size of bitmap to window size.
mglGraphAB
(C++): void
NextFrame ()int
mgl_wnd_next_frame (HMGL
gr)Show next frame if one.
mglGraphAB
(C++): void
PrevFrame ()int
mgl_wnd_prev_frame (HMGL
gr)Show previous frame if one.
mglGraphAB
(C++): void
Animation ()int
mgl_wnd_animation (HMGL
gr)Run/stop slideshow (animation) of frames.
int
mgl_wnd_set_auto_clf (HMGL
gr, int
val)bool
AutoClfClear canvas between drawing. You may switch it off for accumulate previous drawing (for example some points or parts of a picture).
int
mgl_wnd_set_delay (HMGL
gr, int
val)float
DelayDelay for animation in seconds. Default value is 1 sec.
mglGraphAB
(C++, Python): mglPoint
CalcXYZ (int
xs, int
ys)void
mgl_calc_xyz (HMGL
gr, int
xs, int
ys, float *
x, float *
y, float *
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 section Transformation matrix).
mglGraphAB
(C++, Python): mglPoint
CalcScr (mglPoint
p)mglGraphAB
(C++): void
CalcScr (mglPoint
p, int *
xs, int *
ys)void
mgl_calc_scr (HMGL
gr, float
x, float
y, float
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 section Transformation matrix).
int
mgl_wnd_set_show_mouse_pos (HMGL
gr, int
val)float
ShowMousePosSwitch to show or not in the widget the last mouse click position.
mglPoint
LastMousePosLast position of mouse click.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Alexey Balakin on May 2, 2013 using texi2html 1.82.