| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.1 mglGraphAB class
#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).
- Method on
mglGraphAB(C++):const unsigned char *GetBits () - Method on
mglGraph(Python):voidGetRGB (char *buf,intsize) - Method on
mglGraph(Python):voidGetBGRN (char *buf,intsize) - C function:
const unsigned char *mgl_get_rgb (HMGLgr) 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 likefrom mathgl import * gr = mglGraph(); bits='\t'; bits=bits.expandtabs(4*gr.GetWidth()*gr.GetHeight()); gr.GetBGRN(bits, len(bits));
- Method on
mglGraphAB(C++):const unsigned char *GetRGBA () - Method on
mglGraph(Python):voidGetRGBA (char *buf,intsize) - C function:
const unsigned char *mgl_get_rgba (HMGLgr) 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
mglGraphAB(C++, Python):intGetWidth () - Method on
mglGraphAB(C++, Python):intGetHeight () - C function:
intmgl_get_width (HMGLgr) - C function:
intmgl_get_height (HMGLgr) 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.
- Method on mglGraphAB:
voidWindow (intargc,char **argv,int (*draw)(mglGraph *gr,void *p),const char *title,void *par=NULL,void (*reload)(intnext,void *p)=NULL,boolmaximize=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 beNULLfor 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=trueopen 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.
- Method on mglGraphAB:
voidWindow (intargc,char **argv,mglDraw *draw,const char *title,boolmaximize=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
mglDrawand reimplement one or both functions for using this function.
- Method on
mglGraphAB(C++):voidToggleAlpha () - C function:
intmgl_wnd_toggle_alpha (HMGLgr) Switch on/off transparency but do not overwrite switches in user drawing function.
- Method on
mglGraphAB(C++):voidToggleLight () - C function:
intmgl_wnd_toggle_light (HMGLgr) Switch on/off lighting but do not overwrite switches in user drawing function.
- Method on
mglGraphAB(C++):voidToggleZoom () - C function:
intmgl_wnd_toggle_zoom (HMGLgr) Switch on/off zooming by mouse as region selection.
- Method on
mglGraphAB(C++):voidToggleRotate () - C function:
intmgl_wnd_toggle_rotate (HMGLgr) Switch on/off rotation by mouse. Usually, left button is used for rotation, middle button for shift, right button for zoom/perspective.
- Method on
mglGraphAB(C++):voidToggleNo () - C function:
intmgl_wnd_toggle_no (HMGLgr) Switch off all zooming and rotation and restore initial state.
- Method on
mglGraphAB(C++):voidUpdate () - C function:
intmgl_wnd_update (HMGLgr) Update window contents.
- Method on
mglGraphAB(C++):voidReLoad (boolo) - C function:
intmgl_wnd_reload (HMGLgr,intval) Reload user data and update picture.
- Method on
mglGraphAB(C++):voidAdjust () - C function:
intmgl_wnd_adjust (HMGLgr) Adjust size of bitmap to window size.
- Method on
mglGraphAB(C++):voidNextFrame () - C function:
intmgl_wnd_next_frame (HMGLgr) Show next frame if one.
- Method on
mglGraphAB(C++):voidPrevFrame () - C function:
intmgl_wnd_prev_frame (HMGLgr) Show previous frame if one.
- Method on
mglGraphAB(C++):voidAnimation () - C function:
intmgl_wnd_animation (HMGLgr) Run/stop slideshow (animation) of frames.
- Widget option of mglGraphAB:
boolAutoClf Clear canvas between drawing. You may switch it off for accumulate previous drawing (for example some points or parts of a picture).
- Method on
mglGraphAB(C++, Python):mglPointCalcXYZ (intxs,intys) - C function:
voidmgl_calc_xyz (HMGLgr,intxs,intys,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).
- Method on
mglGraphAB(C++, Python):mglPointCalcScr (mglPointp) - Method on
mglGraphAB(C++):voidCalcScr (mglPointp,int *xs,int *ys) - C function:
voidmgl_calc_scr (HMGLgr,floatx,floaty,floatz,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).
- Widget option of mglGraphAB:
floatShowMousePos Switch to show or not in the widget the last mouse click position.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
