From a69bf2d744b5fc1791b56b455586f95fa20b25c5 Mon Sep 17 00:00:00 2001 From: Dimitrios Eftaxiopoulos Date: Sun, 25 Mar 2012 21:34:23 +0300 Subject: [PATCH] Imported Upstream version 2~rc2+svn382 --- examples/fltk_example.cpp | 13 +++++-------- examples/qt_example.cpp | 35 ++++++++++++++++++----------------- include/mgl/data.h | 2 ++ include/mgl/glut.h | 12 ++++++------ lang/mgl.i | 2 ++ src/export_3d.cpp | 15 +++++++-------- texinfo/example_en.texi | 4 ++-- texinfo/widget_en.texi | 8 ++++---- todo.txt | 1 + widgets/glut.cpp | 4 ++-- widgets/window.cpp | 2 ++ 11 files changed, 51 insertions(+), 47 deletions(-) diff --git a/examples/fltk_example.cpp b/examples/fltk_example.cpp index 9e5eb51..0a34df0 100644 --- a/examples/fltk_example.cpp +++ b/examples/fltk_example.cpp @@ -31,24 +31,21 @@ int sample_d(mglGraph *gr); #include mglPoint pnt; // some global variable for changable data void *mgl_fltk_tmp(void *) { mgl_fltk_run(); return 0; } +//#define PTHREAD_SAMPLE //----------------------------------------------------------------------------- int main(int argc,char **argv) { #ifdef PTHREAD_SAMPLE - mglGraphFLTK gr; - gr.Window(argc,argv,NULL,"test",0,0); // create window - gr.ClfOnUpdate = false; - static pthread_t tmp; - pthread_create(&tmp, 0, mgl_fltk_tmp, 0); - pthread_detach(tmp); // run window handling in the separate thread + mglWindow gr("test"); + gr.RunThr(); for(int i=0;i<10;i++) // do calculation { - sleep(2); // which can be very long + sleep(1); // which can be very long pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1); gr.Clf(); // make new drawing gr.Line(mglPoint(),pnt,"Ar2"); char str[10] = "i=0"; str[3] = '0'+i; - gr.Text(mglPoint(),""); + gr.Puts(mglPoint(),""); gr.Update(); // update window } return 0; // finish calculations and close the window diff --git a/examples/qt_example.cpp b/examples/qt_example.cpp index 1a5f13e..bae2696 100644 --- a/examples/qt_example.cpp +++ b/examples/qt_example.cpp @@ -34,36 +34,37 @@ void *mgl_qt_tmp(void *); //----------------------------------------------------------------------------- class Foo : public mglDraw { + mglPoint pnt; // some result of calculation public: + mglWindow *Gr; // graphics to be updated int Draw(mglGraph *gr); + void Calc(); } foo; //----------------------------------------------------- +void Foo::Calc() +{ + for(int i=0;i<30;i++) // do calculation + { + sleep(1); // which can be very long + pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1); + Gr->Update(); // update window + } +} +//----------------------------------------------------- int Foo::Draw(mglGraph *gr) { - gr->Rotate(60,40); + gr->Line(mglPoint(),pnt,"Ar2"); gr->Box(); return 0; } //----------------------------------------------------- +//#define PTHREAD_SAMPLE int main(int argc,char **argv) { #ifdef PTHREAD_SAMPLE - mglWindow gr(1,NULL,"test"); // create window - gr.ClfOnUpdate = false; - static pthread_t tmp; - pthread_create(&tmp, 0, mgl_qt_tmp, 0); - pthread_detach(tmp); // run window handling in the separate thread - for(int i=0;i<10;i++) // do calculation - { - sleep(2); // which can be very long - pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1); - gr.Clf(); // make new drawing - gr.Line(mglPoint(),pnt,"Ar2"); - char str[10] = "i=0"; str[3] = '0'+i; - gr.Text(mglPoint(),""); - gr.Update(); // update window - } - return 0; // finish calculations and close the window + mglWindow gr(&foo,"MathGL examples"); + foo.Gr = &gr; foo.Run(); + return gr.Run(); #else mglWindow *gr; char key = 0; diff --git a/include/mgl/data.h b/include/mgl/data.h index e377cac..bfce511 100644 --- a/include/mgl/data.h +++ b/include/mgl/data.h @@ -423,8 +423,10 @@ inline bool operator==(const mglData &b, const mglData &d) return !memcmp(b.a,d.a,b.nx*b.ny*b.nz*sizeof(mreal)); } #endif //----------------------------------------------------------------------------- +#ifndef SWIG mreal mglLinear(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mreal z); mreal mglSpline3(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mreal z,mreal *dx=0, mreal *dy=0, mreal *dz=0); +#endif //----------------------------------------------------------------------------- /// Integral data transformation (like Fourier 'f' or 'i', Hankel 'h' or None 'n') for amplitude and phase inline mglData mglTransformA(const mglDataA &am, const mglDataA &ph, const char *tr) diff --git a/include/mgl/glut.h b/include/mgl/glut.h index aea0bc6..8060c50 100644 --- a/include/mgl/glut.h +++ b/include/mgl/glut.h @@ -28,7 +28,7 @@ extern "C" { #endif /*****************************************************************************/ void _mgl_key_up(unsigned char ch,int ,int ); -HMGL mgl_create_graph_glut(int (*draw)(HMGL gr, void *p), const char *title, void *par); +HMGL mgl_create_graph_glut(int (*draw)(HMGL gr, void *p), const char *title, void *par, void (*load)(void *p)); /*****************************************************************************/ #ifdef __cplusplus } @@ -80,12 +80,12 @@ private: class mglGLUT: public mglGraph { public: - mglGLUT(int (*draw)(HMGL gr, void *p), const char *title="MathGL", void *par=NULL) : mglGraph(-1) - { gr = mgl_create_graph_glut(draw,title,par); } + mglGLUT(int (*draw)(HMGL gr, void *p), const char *title="MathGL", void *par=0, void (*load)(void *p)=0) : mglGraph(-1) + { gr = mgl_create_graph_glut(draw,title,par,load); } mglGLUT(int (*draw)(mglGraph *gr), const char *title="MathGL") : mglGraph(-1) - { gr = mgl_create_graph_glut(mgl_draw_graph,title,(void*)draw); } - mglGLUT(mglDraw *dr=NULL, const char *title="MathGL") : mglGraph(-1) - { mgl_create_graph_glut(mgl_draw_class,title,dr); } + { gr = mgl_create_graph_glut(mgl_draw_graph,title,(void*)draw,0); } + mglGLUT(mglDraw *dr=0, const char *title="MathGL") : mglGraph(-1) + { mgl_create_graph_glut(mgl_draw_class,title,dr,0); } }; //----------------------------------------------------------------------------- #endif diff --git a/lang/mgl.i b/lang/mgl.i index 12548c6..3e1e112 100644 --- a/lang/mgl.i +++ b/lang/mgl.i @@ -36,6 +36,7 @@ %{ #define SWIG_FILE_WITH_INIT +#include "mgl/config.h" #include "mgl/type.h" #include "mgl/data.h" #include "mgl/mgl.h" @@ -87,6 +88,7 @@ import_array(); %apply (int DIM1, int DIM2, int DIM3, double* IN_ARRAY3) {(int rows, int cols, int slc, const double* d)}; #endif +%include "mgl/config.h" %include "mgl/type.h" %include "mgl/data.h" %include "mgl/mgl.h" diff --git a/src/export_3d.cpp b/src/export_3d.cpp index 67623e8..c56d94e 100644 --- a/src/export_3d.cpp +++ b/src/export_3d.cpp @@ -96,7 +96,7 @@ void mgl_obj_prim(const mglPrim &q, const mglPnt &p, FILE *fp, float size) case '+': fprintf(fp,"v %g %g %g\n",p.x-ss,p.y,p.z); fprintf(fp,"v %g %g %g\n",p.x+ss,p.y,p.z); - fprintf(fp,"v %g %g %g\n",p.x,p.y+ss,p.z); + fprintf(fp,"v %g %g %g\n",p.x,p.y-ss,p.z); fprintf(fp,"v %g %g %g\n",p.x,p.y+ss,p.z); fprintf(fp,"l -4/%ld -3/%ld\n", i,i); fprintf(fp,"l -2/%ld -1/%ld\n", i,i); break; @@ -229,13 +229,11 @@ void mgl_obj_prim(const mglPrim &q, const mglPnt &p, FILE *fp, float size) } break; case 1: fprintf(fp,"l %ld/%ld %ld/%ld\n", n1,n1, n2,n2); break; - case 2: fprintf(fp,"f %ld/%ld/%ld %ld/%ld/%ld %ld/%ld/%ld\n", - n1,n1,n1, n2,n2,n2, n3,n3,n3); break; + case 2: + fprintf(fp,"f %ld/%ld %ld/%ld %ld/%ld\n", n1,n1, n2,n2, n3,n3); break; case 3: - fprintf(fp,"f %ld/%ld/%ld %ld/%ld/%ld %ld/%ld/%ld\n", - n1,n1,n1, n2,n2,n2, n3,n3,n3); - fprintf(fp,"f %ld/%ld/%ld %ld/%ld/%ld %ld/%ld/%ld\n", - n4,n4,n4, n2,n2,n2, n3,n3,n3);break; + fprintf(fp,"f %ld/%ld %ld/%ld %ld/%ld\n", n1,n1, n2,n2, n3,n3); + fprintf(fp,"f %ld/%ld %ld/%ld %ld/%ld\n", n4,n4, n2,n2, n3,n3); break; case 4: break; // TODO: add glyphs export later } } @@ -837,7 +835,7 @@ void mgl_x3d_mdef(HMGL gr, void *fp, bool gz) if(m_P) { m_p=true; m_s=true; } if(m_X) { m_x=true; m_s=true; } if(m_p) mgl_printf(fp, gz, "\n" - "\n" + "\n" "\n\n"); /*if(m_x) mgl_printf(fp, gz, "/m_x {sm sm rm s2 s2 rl 0 sm 2 mul rm sm 2 mul s2 rl d0} def\n"); // TODO * if(m_s) mgl_printf(fp, gz, "/m_s {sm sm rm 0 s2 rl s2 0 rl 0 sm 2 mul rl cp d0} def\n"); @@ -863,6 +861,7 @@ void mgl_x3d_mdef(HMGL gr, void *fp, bool gz) //----------------------------------------------------------------------------- void mgl_x3d_prim(const mglPrim &q, const mglPnt &p, const long *pnt, void *fp,bool gz, float size) { + // /* if(q.type==0) // mark { float x0 = p1.x,y0 = p1.y; diff --git a/texinfo/example_en.texi b/texinfo/example_en.texi index 6ab84ff..adb8704 100644 --- a/texinfo/example_en.texi +++ b/texinfo/example_en.texi @@ -208,12 +208,12 @@ class Foo : public mglDraw { mglPoint pnt; // some result of calculation public: - mglGraph *Gr; // graphics to be updated + mglWindow *Gr; // graphics to be updated int Draw(mglGraph *gr); void Calc(); } foo; //----------------------------------------------------- -int Foo::Calc() +void Foo::Calc() { for(int i=0;i<30;i++) // do calculation { diff --git a/texinfo/widget_en.texi b/texinfo/widget_en.texi index 5c0b522..097d872 100644 --- a/texinfo/widget_en.texi +++ b/texinfo/widget_en.texi @@ -38,12 +38,12 @@ You should inherit yours class from @code{mglDraw} and re-implement one or both This class is derived from mglGraph class (@pxref{MathGL core}). It provide methods for handling window with MathGL graphics. @deftypefn {Constructor on @code{mglWindow}} {} mglWindow (@code{const char *}title=@code{"MathGL"}) -@deftypefnx {Constructor on @code{mglWindow}} {} mglWindow (@code{int} (*draw)(@code{HMGL} gr, @code{void *}p), @code{const char *}title=@code{"MathGL"}, @code{void *}par=@code{NULL}, @code{int} kind=@code{0}) +@deftypefnx {Constructor on @code{mglWindow}} {} mglWindow (@code{int} (*draw)(@code{HMGL} gr, @code{void *}p), @code{const char *}title=@code{"MathGL"}, @code{void *}par=@code{NULL}, @code{int} kind=@code{0}, @code{void} (*reload)(@code{HMGL} gr, @code{void *}p)=0) @deftypefnx {Constructor on @code{mglWindow}} {} mglWindow (@code{int} (*draw)(@code{mglGraph *}gr), @code{const char *}title=@code{"MathGL"}, @code{int} kind=@code{0}) @deftypefnx {Constructor on @code{mglWindow}} {} mglWindow (@code{mglDraw *}draw, @code{const char *}title=@code{"MathGL"}, @code{int} kind=@code{0}) -@deftypefnx {C function} @code{HMGL} mgl_create_graph_qt (@code{int} (*draw)(@code{HMGL} gr, @code{void *}p), @code{const char *}title, @code{void *}par) -@deftypefnx {C function} @code{HMGL} mgl_create_graph_fltk (@code{int} (*draw)(@code{HMGL} gr, @code{void *}p), @code{const char *}title, @code{void *}par) -@deftypefnx {C function} @code{HMGL} mgl_create_graph_glut (@code{int} (*draw)(@code{HMGL} gr, @code{void *}p), @code{const char *}title, @code{void *}par) +@deftypefnx {C function} @code{HMGL} mgl_create_graph_qt (@code{int} (*draw)(@code{HMGL} gr, @code{void *}p), @code{const char *}title, @code{void *}par, @code{void} (*reload)(@code{HMGL} gr, @code{void *}p)) +@deftypefnx {C function} @code{HMGL} mgl_create_graph_fltk (@code{int} (*draw)(@code{HMGL} gr, @code{void *}p), @code{const char *}title, @code{void *}par, @code{void} (*reload)(@code{HMGL} gr, @code{void *}p)) +@deftypefnx {C function} @code{HMGL} mgl_create_graph_glut (@code{int} (*draw)(@code{HMGL} gr, @code{void *}p), @code{const char *}title, @code{void *}par, @code{void} (*reload)(@code{HMGL} gr, @code{void *}p)) Creates a window for plotting. Parameter @var{draw} sets a pointer to drawing function (this is the name of function) or instance of @code{mglDraw} class. 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 @var{draw} can be @code{NULL} for displaying static bitmaps only (no animation or slides). Parameter @var{title} sets the title of the window. Parameter @var{par} contains pointer to data for the plotting function @var{draw}. Parameter @var{kind} may have following values: @samp{0} -- use FLTK window, @samp{1} -- use Qt window. diff --git a/todo.txt b/todo.txt index 2ea7106..b82787b 100644 --- a/todo.txt +++ b/todo.txt @@ -6,6 +6,7 @@ Device 0 (VID=0502 and PID=337d) is UNKNOWN. 1. Add sample for window in python/octave (like pthread) -- Docs 2. Add help about cmake into the "Installation and using" -- after build system will be ready 3. Export to X3D +4. Check RunThr() ============= FOR V.2.1 ======== diff --git a/widgets/glut.cpp b/widgets/glut.cpp index 66b56f6..f4f3664 100644 --- a/widgets/glut.cpp +++ b/widgets/glut.cpp @@ -186,10 +186,10 @@ void mglCanvasGLUT::Window(int argc, char **argv,int (*draw)(mglBase *gr, void * glDeleteLists(1,NumFig); } //----------------------------------------------------------------------------- -HMGL mgl_create_graph_glut(int (*draw)(HMGL gr, void *p), const char *title, void *par) +HMGL mgl_create_graph_glut(int (*draw)(HMGL gr, void *p), const char *title, void *par, void (*load)(void *p)) { mglCanvasGLUT *g = new mglCanvasGLUT; - g->Window(0,0,draw,title,par); + g->Window(0,0,draw,title,par, load); return g; } //----------------------------------------------------------------------------- diff --git a/widgets/window.cpp b/widgets/window.cpp index 70a69fd..61a9e7b 100644 --- a/widgets/window.cpp +++ b/widgets/window.cpp @@ -181,9 +181,11 @@ void *mgl_fltk_tmp(void *) //----------------------------------------------------------------------------- int mgl_fltk_thr() // NOTE: Qt couldn't be running in non-primary thread { +#if MGL_HAVE_PTHREAD static pthread_t thr; pthread_create(&thr,0,mgl_fltk_tmp,0); pthread_detach(thr); +#endif return 0; // stupid, but I don't want keep result returned by Fl::Run() } //----------------------------------------------------------------------------- -- 2.30.2