From 09716c8c88067f867e7b3821c4a0f8429df39e7d Mon Sep 17 00:00:00 2001 From: Dimitrios Eftaxiopoulos Date: Fri, 16 Mar 2012 17:23:02 +0200 Subject: [PATCH] Imported Upstream version 2~rc2+svn367 --- CMakeLists.txt | 379 ++++---- examples/full_test.cpp | 84 +- include/CMakeLists.txt | 25 +- include/config.h.in | 18 + include/mgl/data.h | 8 +- lang/CMakeLists.txt | 4 +- mgllab/CMakeLists.txt | 5 +- src/CMakeLists.txt | 82 +- src/cont.cpp | 8 +- src/plot.cpp | 8 +- src/prim.cpp | 9 +- texinfo/CMakeLists.txt | 4 +- texinfo/Makefile.am | 2 +- texinfo/core_en.texi | 19 +- texinfo/ex_mgl_en.texi | 2 +- texinfo/example_en.texi | 1932 ++++++++++++++++++++++++++++++++++----- todo.txt | 25 +- udav/CMakeLists.txt | 19 +- utils/CMakeLists.txt | 27 +- widgets/CMakeLists.txt | 49 +- 20 files changed, 2075 insertions(+), 634 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01a9fee..b83f692 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,112 +24,105 @@ option(enable-qt "Enable Qt4 widget") option(enable-python "Enable python interface") option(enable-octave "Enable octave interface") option(enable-doc "Enable documentation building") -if(enable-double) - set(use_double 1) -endif(enable-double) -if((enable-all OR enable-gsl) AND (NOT enable-lgpl) ) - set(use_gsl 1) -endif((enable-all OR enable-gsl) AND (NOT enable-lgpl) ) -if(enable-all OR enable-ltdl) - set(use_ltdl 1) -endif(enable-all OR enable-ltdl) -if(enable-all OR enable-pthread) - set(use_pthread 1) -endif(enable-all OR enable-pthread) -if(enable-all OR enable-jpeg) - set(use_jpeg 1) -endif(enable-all OR enable-jpeg) -if((enable-all OR enable-u3d OR enable-pdf) AND (NOT enable-lgpl) ) - set(use_u3d 1) -endif((enable-all OR enable-u3d OR enable-pdf) AND (NOT enable-lgpl) ) -if((enable-all OR enable-pdf) AND (NOT enable-lgpl) ) - set(use_pdf 1) -endif((enable-all OR enable-pdf) AND (NOT enable-lgpl) ) -if(enable-all OR enable-gif) - set(use_gif 1) -endif(enable-all OR enable-gif) -if(enable-all OR enable-opengl) - set(use_opengl 1) -endif(enable-all OR enable-opengl) -if((enable-all OR enable-hdf4) AND (NOT enable-lgpl) ) - set(use_hdf4 1) -endif((enable-all OR enable-hdf4) AND (NOT enable-lgpl) ) -if((enable-all OR enable-hdf5) AND (NOT enable-lgpl) ) - set(use_hdf5 1) -endif((enable-all OR enable-hdf5) AND (NOT enable-lgpl) ) -if(enable-hdf5_18) - set(use_hdf5_18 1) -endif(enable-hdf5_18) -if((enable-all OR enable-glut) AND (NOT enable-lgpl) ) - set(use_glut 1) -endif((enable-all OR enable-glut) AND (NOT enable-lgpl) ) -if((enable-all OR enable-fltk) AND (NOT enable-lgpl) ) - set(use_fltk 1) -endif((enable-all OR enable-fltk) AND (NOT enable-lgpl) ) -if((enable-all OR enable-wx) AND (NOT enable-lgpl) ) - set(use_wx 0) -endif((enable-all OR enable-wx) AND (NOT enable-lgpl) ) -if((enable-all OR enable-qt) AND (NOT enable-lgpl) ) - set(use_qt 1) -endif((enable-all OR enable-qt) AND (NOT enable-lgpl) ) -if(enable-all OR enable-doc) - set(use_doc 1) -endif(enable-all OR enable-doc) -if((enable-langall OR enable-python) AND (NOT enable-lgpl) ) - set(use_python 1) -endif((enable-langall OR enable-python) AND (NOT enable-lgpl) ) -if((enable-langall OR enable-octave) AND (NOT enable-lgpl) ) - set(use_octave 1) -endif((enable-langall OR enable-octave) AND (NOT enable-lgpl) ) -if(use_glut AND NOT use_opengl) - message(SEND_ERROR "You have to enable OpenGL if you plan to use GLUT.") -endif(use_glut AND NOT use_opengl) +include_directories( ${MathGL_SOURCE_DIR}/include ${MathGL_BINARY_DIR}/include) -include_directories( ${MathGL_SOURCE_DIR}/include ) +if(enable-double) + set(MGL_USE_DOUBLE 1) +else(enable-double) + set(MGL_USE_DOUBLE 0) +endif(enable-double) -include(FindOpenGL) -if(NOT OPENGL_FOUND) - if(use_opengl) - message(SEND_ERROR "Couldn't find OpenGL libraries.") - endif(use_opengl) -endif(NOT OPENGL_FOUND) +include(FindZLIB) +if(NOT ZLIB_FOUND) + message(SEND_ERROR "Couldn't find ZLIB library.") +endif(NOT ZLIB_FOUND) include(FindPNG) if(NOT PNG_FOUND) message(SEND_ERROR "Couldn't find PNG libraries.") endif(NOT PNG_FOUND) -find_library(GSL_LIB gsl) -find_library(GSL_CBLAS_LIB gslcblas) -find_path(GSL_INCLUDE_DIR gsl/gsl_fft_complex.h) -if(NOT GSL_LIB OR NOT GSL_CBLAS_LIB OR NOT GSL_INCLUDE_DIR) - if(use_gsl) +if((enable-all OR enable-gsl) AND (NOT enable-lgpl) ) + set(MGL_HAVE_GSL 1) + find_library(GSL_LIB gsl) + find_library(GSL_CBLAS_LIB gslcblas) + find_path(GSL_INCLUDE_DIR gsl/gsl_fft_complex.h) + if(NOT GSL_LIB OR NOT GSL_CBLAS_LIB OR NOT GSL_INCLUDE_DIR) message(SEND_ERROR "${GSL_LIB}") message(SEND_ERROR "${GSL_CBLAS_LIB}") message(SEND_ERROR "${GSL_INCLUDE_DIR}") message(SEND_ERROR "Couldn't find GSL libraries.") - endif(use_gsl) -endif(NOT GSL_LIB OR NOT GSL_CBLAS_LIB OR NOT GSL_INCLUDE_DIR) + endif(NOT GSL_LIB OR NOT GSL_CBLAS_LIB OR NOT GSL_INCLUDE_DIR) +else((enable-all OR enable-gsl) AND (NOT enable-lgpl) ) + set(MGL_HAVE_GSL 0) +endif((enable-all OR enable-gsl) AND (NOT enable-lgpl) ) -find_library(LTDL_LIB ltdl) -find_path(LTDL_INCLUDE_DIR ltdl.h) -if(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR) - if(use_ltdl) +if(enable-all OR enable-ltdl) + set(MGL_HAVE_LTDL 1) + find_library(LTDL_LIB ltdl) + find_path(LTDL_INCLUDE_DIR ltdl.h) + if(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR) message(SEND_ERROR "${LTDL_LIB}") message(SEND_ERROR "${LTDL_INCLUDE_DIR}") message(SEND_ERROR "Couldn't find LTDL library.") - endif(use_ltdl) -endif(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR) + endif(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR) +else(enable-all OR enable-ltdl) + set(MGL_HAVE_LTDL 0) +endif(enable-all OR enable-ltdl) -include(FindThreads) -if(NOT CMAKE_USE_PTHREADS_INIT) - if(use_pthread) +if(enable-all OR enable-pthread) + set(MGL_HAVE_PTHREAD 1) + include(FindThreads) + if(NOT CMAKE_USE_PTHREADS_INIT) message(SEND_ERROR "Couldn't find POSIX threads library.") - endif(use_pthread) -endif(NOT CMAKE_USE_PTHREADS_INIT) + endif(NOT CMAKE_USE_PTHREADS_INIT) +else(enable-all OR enable-pthread) + set(MGL_HAVE_PTHREAD 0) +endif(enable-all OR enable-pthread) + +if((enable-all OR enable-hdf4) AND (NOT enable-lgpl) ) + set(MGL_HAVE_HDF4 1) + find_library(HDF4_LIB df) + find_library(HDF4MF_LIB mfhdf) + find_path(HDF4_INCLUDE_DIR hdf/mfhdf.h) + if(NOT HDF4_LIB OR NOT HDF4MF_LIB OR NOT HDF4_INCLUDE_DIR) + message(SEND_ERROR "${HDF4_LIB}") + message(SEND_ERROR "${HDF4MF_LIB}") + message(SEND_ERROR "${HDF4_INCLUDE_DIR}") + message(SEND_ERROR "Couldn't find HDF4 libraries.") + endif(NOT HDF4_LIB OR NOT HDF4MF_LIB OR NOT HDF4_INCLUDE_DIR) +else((enable-all OR enable-hdf4) AND (NOT enable-lgpl) ) + set(MGL_HAVE_HDF4 0) +endif((enable-all OR enable-hdf4) AND (NOT enable-lgpl) ) + +if((enable-all OR enable-hdf5 OR enable-hdf5_18) AND (NOT enable-lgpl) ) + set(MGL_HAVE_HDF5 1) + if(enable-hdf5_18) + set(MGL_HAVE_HDF5_18 1) + else(enable-hdf5_18) + set(MGL_HAVE_HDF5_18 0) + endif(enable-hdf5_18) + include(FindHDF5) + if(NOT HDF5_FOUND) + message(SEND_ERROR "Couldn't find HDF5 library.") + endif(NOT HDF5_FOUND) +else((enable-all OR enable-hdf5 OR enable-hdf5_18) AND (NOT enable-lgpl) ) + set(MGL_HAVE_HDF5 0) +endif((enable-all OR enable-hdf5 OR enable-hdf5_18) AND (NOT enable-lgpl) ) -if(use_u3d) +if(enable-all OR enable-jpeg) + set(MGL_HAVE_JPEG 1) + include(FindJPEG) + if(NOT JPEG_FOUND) + message(SEND_ERROR "Couldn't find JPEG library.") + endif(NOT JPEG_FOUND) +else(enable-all OR enable-jpeg) + set(MGL_HAVE_JPEG 0) +endif(enable-all OR enable-jpeg) + +if((enable-all OR enable-u3d OR enable-pdf) AND (NOT enable-lgpl) ) + set(MGL_HAVE_U3D 1) find_library(U3D_LIB IDTF) if(NOT U3D_LIB) message(STATUS "Couldn't find U3D libraries.") @@ -140,9 +133,12 @@ if(use_u3d) endif(NOT U3D_INCLUDE_DIR) message(STATUS "Found U3D libraries at: ${U3D_LIB}") message(STATUS "Found U3D headers: ${U3D_INCLUDE_DIR}") -endif(use_u3d) +else((enable-all OR enable-u3d OR enable-pdf) AND (NOT enable-lgpl) ) + set(MGL_HAVE_U3D 0) +endif((enable-all OR enable-u3d OR enable-pdf) AND (NOT enable-lgpl) ) -if(use_pdf) +if((enable-all OR enable-pdf) AND (NOT enable-lgpl) ) + set(MGL_HAVE_PDF 1) find_library(HPDF_LIB hpdf) if(NOT HPDF_LIB) message(STATUS "Couldn't find libHaru.") @@ -153,139 +149,138 @@ if(use_pdf) endif(NOT HPDF_INCLUDE_DIR) message(STATUS "Found libHaru library at: ${HPDF_LIB}") message(STATUS "Found libHaru headers: ${HPDF_INCLUDE_DIR}") -endif(use_pdf) - -include(FindZLIB) -if(NOT ZLIB_FOUND) - message(SEND_ERROR "Couldn't find ZLIB library.") -endif(NOT ZLIB_FOUND) - -include(FindJPEG) -if(NOT JPEG_FOUND) - if(use_jpeg) - message(SEND_ERROR "Couldn't find JPEG library.") - endif(use_jpeg) -endif(NOT JPEG_FOUND) +else((enable-all OR enable-pdf) AND (NOT enable-lgpl) ) + set(MGL_HAVE_PDF 0) +endif((enable-all OR enable-pdf) AND (NOT enable-lgpl) ) -include(FindGIF) -if(NOT GIF_FOUND) - if(use_gif) +if(enable-all OR enable-gif) + set(MGL_HAVE_GIF 1) + include(FindGIF) + if(NOT GIF_FOUND) message(SEND_ERROR "Couldn't find GIF library.") - endif(use_gif) -endif(NOT GIF_FOUND) - -find_library(HDF4_LIB df) -find_library(HDF4MF_LIB mfhdf) -find_path(HDF4_INCLUDE_DIR hdf/mfhdf.h) -if(NOT HDF4_LIB OR NOT HDF4MF_LIB OR NOT HDF4_INCLUDE_DIR) - if(use_hdf4) - message(SEND_ERROR "${HDF4_LIB}") - message(SEND_ERROR "${HDF4MF_LIB}") - message(SEND_ERROR "${HDF4_INCLUDE_DIR}") - message(SEND_ERROR "Couldn't find HDF4 libraries.") - endif(use_hdf4) -endif(NOT HDF4_LIB OR NOT HDF4MF_LIB OR NOT HDF4_INCLUDE_DIR) + endif(NOT GIF_FOUND) +else(enable-all OR enable-gif) + set(MGL_HAVE_GIF 0) +endif(enable-all OR enable-gif) -include(FindHDF5) -if(NOT HDF5_FOUND) - if(use_hdf5 OR use_hdf5_18) - message(SEND_ERROR "Couldn't find HDF5 library.") - endif(use_hdf5 OR use_hdf5_18) -endif(NOT HDF5_FOUND) +if(enable-all OR enable-opengl) + set(MGL_HAVE_OPENGL 1) + include(FindOpenGL) + if(NOT OPENGL_FOUND) + message(SEND_ERROR "Couldn't find OpenGL libraries.") + endif(NOT OPENGL_FOUND) +else(enable-all OR enable-opengl) + set(MGL_HAVE_OPENGL 0) +endif(enable-all OR enable-opengl) -include(FindGLUT) -if(NOT GLUT_FOUND) - if(use_glut) +if((enable-all OR enable-glut) AND (NOT enable-lgpl) ) + set(MGL_HAVE_GLUT 1) + if(NOT MGL_HAVE_OPENGL) + message(SEND_ERROR "You have to enable OpenGL if you plan to use GLUT.") + endif(NOT MGL_HAVE_OPENGL) + include(FindGLUT) + if(NOT GLUT_FOUND) message(SEND_ERROR "Couldn't find GLUT library.") - endif(use_glut) -endif(NOT GLUT_FOUND) + endif(NOT GLUT_FOUND) +else((enable-all OR enable-glut) AND (NOT enable-lgpl) ) + set(MGL_HAVE_GLUT 0) +endif((enable-all OR enable-glut) AND (NOT enable-lgpl) ) -include(FindFLTK) -if(NOT FLTK_FOUND) - if(use_fltk) +if((enable-all OR enable-fltk) AND (NOT enable-lgpl) ) + set(MGL_HAVE_FLTK 1) + include(FindFLTK) + if(NOT FLTK_FOUND) message(SEND_ERROR "Couldn't find FLTK library.") - endif(use_fltk) -endif(NOT FLTK_FOUND) + endif(NOT FLTK_FOUND) +else((enable-all OR enable-fltk) AND (NOT enable-lgpl) ) + set(MGL_HAVE_FLTK 0) +endif((enable-all OR enable-fltk) AND (NOT enable-lgpl) ) -FIND_PACKAGE(wxWidgets COMPONENTS base core gl) -if(NOT wxWidgets_FOUND) - if(use_wx) +if((enable-all OR enable-wx) AND (NOT enable-lgpl) ) + set(MGL_HAVE_WX 0) + FIND_PACKAGE(wxWidgets COMPONENTS base core gl) + if(NOT wxWidgets_FOUND) message(SEND_ERROR "Couldn't find wxWidgets library.") - endif(use_wx) -endif(NOT wxWidgets_FOUND) + endif(NOT wxWidgets_FOUND) +else((enable-all OR enable-wx) AND (NOT enable-lgpl) ) + set(MGL_HAVE_WX 0) +endif((enable-all OR enable-wx) AND (NOT enable-lgpl) ) -FIND_PACKAGE(Qt4) -if(NOT QT4_FOUND) - if(use_qt) +if((enable-all OR enable-qt) AND (NOT enable-lgpl) ) + set(MGL_HAVE_QT 1) + FIND_PACKAGE(Qt4) + if(NOT QT4_FOUND) message(SEND_ERROR "Couldn't find Qt4 library.") - endif(use_qt) -endif(NOT QT4_FOUND) - - -FIND_PACKAGE(SWIG) -if(NOT SWIG_FOUND) - if(use_python OR use_octave) - message(SEND_ERROR "Couldn't find swig needed for interfaces compiling.") - endif(use_python OR use_octave) -endif(NOT SWIG_FOUND) + endif(NOT QT4_FOUND) +else((enable-all OR enable-qt) AND (NOT enable-lgpl) ) + set(MGL_HAVE_QT 0) +endif((enable-all OR enable-qt) AND (NOT enable-lgpl) ) +if((enable-langall OR enable-python) AND (NOT enable-lgpl) ) + set(MGL_HAVE_PYTHON 1) # include(FindPythonInterp) # if(NOT PYTHONLIBS_FOUND) # if(use_python) # message(SEND_ERROR "Couldn't find python interpreter.") # endif(use_python) # endif(NOT PYTHONINTERP_FOUND) -FIND_PACKAGE(PythonLibs) -#include(FindPythonLibs) -if(NOT PYTHONLIBS_FOUND) - if(use_python) + FIND_PACKAGE(PythonLibs) + if(NOT PYTHONLIBS_FOUND) message(SEND_ERROR "Couldn't find python development libraries.") - endif(use_python) -endif(NOT PYTHONLIBS_FOUND) + endif(NOT PYTHONLIBS_FOUND) +else((enable-langall OR enable-python) AND (NOT enable-lgpl) ) + set(MGL_HAVE_PYTHON 0) +endif((enable-langall OR enable-python) AND (NOT enable-lgpl) ) -find_path(OCTAVE_INCLUDE_DIR octave/oct.h) -if(NOT OCTAVE_INCLUDE_DIR) - if(use_octave) +if((enable-langall OR enable-octave) AND (NOT enable-lgpl) ) + set(MGL_HAVE_OCTAVE 1) + find_path(OCTAVE_INCLUDE_DIR octave/oct.h) + if(NOT OCTAVE_INCLUDE_DIR) message(SEND_ERROR "Couldn't find octave/oct.h needed for octave interfaces compiling.") - endif(use_octave) -endif(NOT OCTAVE_INCLUDE_DIR) -find_program(oct_prog octave) -if(NOT oct_prog) - if(use_octave) + endif(NOT OCTAVE_INCLUDE_DIR) + find_program(oct_prog octave) + if(NOT oct_prog) message(SEND_ERROR "Couldn't find octave needed for octave interfaces compiling.") - endif(use_octave) -endif(NOT oct_prog) -find_program(oct_mk mkoctfile) -if(NOT oct_mk) - if(use_octave) + endif(NOT oct_prog) + find_program(oct_mk mkoctfile) + if(NOT oct_mk) message(SEND_ERROR "Couldn't find mkoctfile needed for octave interfaces compiling.") - endif(use_octave) -endif(NOT oct_mk) + endif(NOT oct_mk) +else((enable-langall OR enable-octave) AND (NOT enable-lgpl) ) + set(MGL_HAVE_OCTAVE 0) +endif((enable-langall OR enable-octave) AND (NOT enable-lgpl) ) + +if(enable-all OR enable-doc) + set(MGL_HAVE_DOC 1) + find_program(findmi makeinfo) + if(NOT findmi) + message(SEND_ERROR "Couldn't find makeinfo needed for documentation building.") + endif(NOT findmi) + find_program(findth texi2html) + if(NOT findth) + message(SEND_ERROR "Couldn't find texi2html needed for documentation building.") + endif(NOT findth) + find_program(findtp texi2pdf) + if(NOT findtp) + message(SEND_ERROR "Couldn't find texi2pdf needed for documentation building.") + endif(NOT findtp) +else(enable-all OR enable-doc) + set(MGL_HAVE_DOC 0) +endif(enable-all OR enable-doc) + +if(MGL_HAVE_PYTHON OR MGL_HAVE_OCTAVE) + FIND_PACKAGE(SWIG) + if(NOT SWIG_FOUND) + message(SEND_ERROR "Couldn't find swig needed for interfaces compiling.") + endif(NOT SWIG_FOUND) +endif(MGL_HAVE_PYTHON OR MGL_HAVE_OCTAVE) + #execute_process( # COMMAND ${oct_prog} -q --eval \'strcat\(octave_config_info\("canonical_host_type"\), "-", octave_config_info\("api_version"\)\)'|sed -e 's/ans = //' # OUTPUT_VARIABLE OCTAVE_ARCH # ) #message(SEND_ERROR "${OCTAVE_ARCH}") -find_program(findmi makeinfo) -if(NOT findmi) - if(use_doc) - message(SEND_ERROR "Couldn't find makeinfo needed for documentation building.") - endif(use_doc) -endif(NOT findmi) -find_program(findth texi2html) -if(NOT findth) - if(use_doc) - message(SEND_ERROR "Couldn't find texi2html needed for documentation building.") - endif(use_doc) -endif(NOT findth) -find_program(findtp texi2pdf) -if(NOT findtp) - if(use_doc) - message(SEND_ERROR "Couldn't find texi2pdf needed for documentation building.") - endif(use_doc) -endif(NOT findtp) - if(UNIX) add_definitions(-DNO_COLOR_ARRAY) endif(UNIX) diff --git a/examples/full_test.cpp b/examples/full_test.cpp index 109564b..f4cf484 100644 --- a/examples/full_test.cpp +++ b/examples/full_test.cpp @@ -49,43 +49,19 @@ void smgl_combined(mglGraph *gr); void save(mglGraph *gr,const char *name,const char *suf); void test(mglGraph *gr) { - //double v [5] = {0.000001, 10.000001, 20.000001, 30.000001, 39.999999}, *vv, Value; - // ERROR ERROR ERROR - //----------------------------------------------------------------- - double v [5] = {0.0, 10.0, 20.0, 30.0, 40.0}, *vv, Value; - //----------------------------------------------------------------- - double x [4] = {0, 10, 20, 30}, *xx; - double y [5] = {0, 10, 20, 30, 40}, *yy; - int - iy,ix,iz; - mglData Z(4,5), V(6), X(5), Y(4); - for (ix=0;ix<4;ix++){ - for (iy=0;iy<5;iy++) { - Z.Put(iy*10,ix,iy); - } + int i, n=1000; + mglData x(n),y(n),z(n); + for(i=0;iDefaultPlotParam(); - gr->InPlot(0.0, 0.7, 0.0, 1.0); - gr->SetRanges(0,30,-5,45,-80,70); -// gr->Axis(mglPoint(0,-5),mglPoint(30,45)); - gr->SetTicks('x', 5, 4); // sets tick step to 5 - gr->SetTicks('y', 5, 4); // and draws 4 subticks - gr->Axis("xy"); - gr->Box(); - gr->Colorbar(); - gr->Dens(X,Y,Z); - // Color Gradient - gr->Cont(V,X,Y,Z,"tk"); - // Without Color ERROR ERROR ERROR - + if(!mini) gr->Title("Dots sample"); + gr->Rotate(50,60); gr->Box(); gr->Dots(x,y,z); + return; + mglParse par; par.AllowSetSize(true); FILE *fp=fopen("/home/balakin/mgl/att/put.mgl","rt"); @@ -439,7 +415,8 @@ void smgl_area(mglGraph *gr) gr->Area(xc,yc,z,"r"); } //----------------------------------------------------------------------------- -const char *mmgl_plot="subplot 2 2 0 '':title 'Plot plot (default)':box:plot y\nsubplot 2 2 2 '':title ''!' style; 'rgb' palette':box:plot y 'o!rgb'\n" +const char *mmgl_plot="subplot 2 2 0 '':title 'Plot plot (default)':box:plot y\n" +"subplot 2 2 2 '':title ''!' style; 'rgb' palette':box:plot y 'o!rgb'\nsubplot 2 2 3 '':title 'just markers':box:plot y ' +'\n" "new yc 30 'sin(pi*x)':new xc 30 'cos(pi*x)':new z 30 'x'\nsubplot 2 2 1:title '3d variant':rotate 50 60:box:plot xc yc z 'rs'\n"; void smgl_plot(mglGraph *gr) { @@ -448,18 +425,19 @@ void smgl_plot(mglGraph *gr) gr->Box(); gr->Plot(y); if(mini) return; gr->SubPlot(2,2,2,""); gr->Title("'!' style; 'rgb' palette"); gr->Box(); gr->Plot(y,"o!rgb"); + gr->SubPlot(2,2,3,""); gr->Title("just markers"); gr->Box(); gr->Plot(y," +"); gr->SubPlot(2,2,1); gr->Title("3d variant"); gr->Rotate(50,60); gr->Box(); mglData yc(30), xc(30), z(30); z.Modify("2*x-1"); yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); gr->Plot(xc,yc,z,"rs"); } //----------------------------------------------------------------------------- -const char *mmgl_tens="subplot 2 2 0 '':title 'Plot plot (default)':box:tens y(:.0) y(:,1)\nsubplot 2 2 1 '':title '' ' style':box:plot y(:.0) y(:,1) 'o '\n" +const char *mmgl_tens="subplot 2 2 0 '':title 'Tens plot (default)':box:tens y(:.0) y(:,1)\nsubplot 2 2 1 '':title '' ' style':box:plot y(:.0) y(:,1) 'o '\n" "new yc 30 'sin(pi*x)':new xc 30 'cos(pi*x)':new z 30 'x'\nsubplot 2 2 1:title '3d variant':rotate 50 60:box:tens xc yc z z 's'\n"; void smgl_tens(mglGraph *gr) { mglData y; mgls_prepare1d(&y); gr->SetOrigin(0,0,0); - if(!mini) { gr->SubPlot(2,2,0,""); gr->Title("Plot plot (default)"); } + if(!mini) { gr->SubPlot(2,2,0,""); gr->Title("Tens plot (default)"); } gr->Box(); gr->Tens(y.SubData(-1,0), y.SubData(-1,1)); if(mini) return; gr->SubPlot(2,2,2,""); gr->Title("' ' style"); gr->Box(); gr->Tens(y.SubData(-1,0), y.SubData(-1,1),"o "); @@ -1241,7 +1219,7 @@ void smgl_surfa(mglGraph *gr) { mglData a,b; mgls_prepare2d(&a,&b); if(!mini) gr->Title("SurfA plot"); gr->Rotate(50,60); - gr->Light(true); gr->Box(); gr->SurfA(a,b); + gr->Alpha(true); gr->Light(true); gr->Box(); gr->SurfA(a,b); } //----------------------------------------------------------------------------- const char *mmgl_tile="title 'Tile plot':rotate 50 60:box:tile a\n"; @@ -1256,7 +1234,7 @@ const char *mmgl_tiles="title 'Tiles plot':box:tiles a b\n"; void smgl_tiles(mglGraph *gr) { mglData a,b; mgls_prepare2d(&a,&b); - if(!mini) {gr->SubPlot(1,1,0,""); gr->Title("Tile plot");} + if(!mini) {gr->SubPlot(1,1,0,""); gr->Title("TileS plot");} gr->Box(); gr->TileS(a,b); } //----------------------------------------------------------------------------- @@ -1700,7 +1678,7 @@ void smgl_dat_diff(mglGraph *gr) // differentiate } //----------------------------------------------------------------------------- const char *mmgl_data_extra=""; // TODO add later -void smgl_dat_exta(mglGraph *gr) // differentiate +void smgl_dat_extra(mglGraph *gr) // differentiate { gr->SubPlot(2,2,0,""); gr->Title("Envelop sample"); mglData d1(1000); gr->Fill(d1,"exp(-8*x^2)*sin(10*pi*x)"); @@ -1803,6 +1781,25 @@ void smgl_triplot(mglGraph *gr) gr->TriPlot(tt,uu,vv,ww,"k#"); } //----------------------------------------------------------------------------- +const char *mmgl_dots="new t 1000 'pi*(rnd-0.5)':new f 1000 '2*pi*rnd'\n" +"copy x 0.9*cos(t)*cos(f):copy y 0.9*cos(t)*sin(f):copy z 0.6*sin(t)\n" +"title 'Dots sample':rotate 50 60\nbox:dots x y z\n"; +void smgl_dots(mglGraph *gr) +{ + int i, n=1000; + mglData x(n),y(n),z(n); + for(i=0;iTitle("Dots sample"); + gr->Rotate(50,60); gr->Box(); gr->Dots(x,y,z); +} +//----------------------------------------------------------------------------- + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -2038,11 +2035,12 @@ mglSample samp[] = { {"curvcoor", smgl_curvcoor}, {"cut", smgl_cut}, {"dat_diff", smgl_dat_diff}, - {"dat_exta", smgl_dat_exta}, + {"dat_extra", smgl_dat_extra}, {"dens", smgl_dens}, {"dens_xyz", smgl_dens_xyz}, {"densa", smgl_densa}, {"dew", smgl_dew}, + {"dots", smgl_dots}, {"error", smgl_error}, {"fall", smgl_fall}, {"fit", smgl_fit}, diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 13e9724..05f578e 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,10 +1,4 @@ -if(use_double) - set(MGL_USE_DOUBLE 1) -else(use_double) - set(MGL_USE_DOUBLE 0) -endif(use_double) - -configure_file(${CMAKE_SOURCE_DIR}/include/config.h.in ${CMAKE_SOURCE_DIR}/include/mgl/config.h) +configure_file(${MathGL_SOURCE_DIR}/include/config.h.in ${MathGL_BINARY_DIR}/include/mgl/config.h) set(MGL_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/include/mgl") install(DIRECTORY mgl/ DESTINATION ${MGL_INCLUDE_PATH} @@ -18,15 +12,16 @@ install(DIRECTORY mgl/ DESTINATION ${MGL_INCLUDE_PATH} PATTERN "*.pas" PATTERN "*.h") -if(use_fltk) +install(FILES ${MathGL_BINARY_DIR}/include/mgl/config.h DESTINATION ${MGL_INCLUDE_PATH}) +if(MGL_HAVE_FLTK) install(FILES mgl/fltk.h DESTINATION ${MGL_INCLUDE_PATH}) -endif(use_fltk) -if(use_glut) +endif(MGL_HAVE_FLTK) +if(MGL_HAVE_GLUT) install(FILES mgl/glut.h DESTINATION ${MGL_INCLUDE_PATH}) -endif(use_glut) -if(use_wx) +endif(MGL_HAVE_GLUT) +if(MGL_HAVE_WX) install(FILES mgl/wx.h DESTINATION ${MGL_INCLUDE_PATH}) -endif(use_wx) -if(use_qt) +endif(MGL_HAVE_WX) +if(MGL_HAVE_QT) install(FILES mgl/qt.h DESTINATION ${MGL_INCLUDE_PATH}) -endif(use_qt) +endif(MGL_HAVE_QT) diff --git a/include/config.h.in b/include/config.h.in index b73a9d7..a4f947c 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -1,3 +1,21 @@ /* This define enables double precision in MathGL */ #define MGL_USE_DOUBLE ${MGL_USE_DOUBLE} +#define MGL_HAVE_GSL ${MGL_HAVE_GSL} +#define MGL_HAVE_LTDL ${MGL_HAVE_LTDL} +#define MGL_HAVE_PTHREAD ${MGL_HAVE_PTHREAD} +#define MGL_HAVE_HDF4 ${MGL_HAVE_HDF4} +#define MGL_HAVE_HDF5 ${MGL_HAVE_HDF5} +#define MGL_HAVE_HDF5_18 ${MGL_HAVE_HDF5_18} +#define MGL_HAVE_JPEG ${MGL_HAVE_JPEG} +#define MGL_HAVE_U3D ${MGL_HAVE_U3D} +#define MGL_HAVE_PDF ${MGL_HAVE_PDF} +#define MGL_HAVE_GIF ${MGL_HAVE_GIF} +#define MGL_HAVE_OPENGL ${MGL_HAVE_OPENGL} +#define MGL_HAVE_GLUT ${MGL_HAVE_GLUT} +#define MGL_HAVE_FLTK ${MGL_HAVE_FLTK} +#define MGL_HAVE_WX ${MGL_HAVE_WX} +#define MGL_HAVE_QT ${MGL_HAVE_QT} +#define MGL_HAVE_PYTHON ${MGL_HAVE_PYTHON} +#define MGL_HAVE_OCTAVE ${MGL_HAVE_OCTAVE} +#define MGL_HAVE_DOC ${MGL_HAVE_DOC} diff --git a/include/mgl/data.h b/include/mgl/data.h index 2e827a9..71d8f4d 100644 --- a/include/mgl/data.h +++ b/include/mgl/data.h @@ -330,11 +330,11 @@ public: inline mglData(long xx=1,long yy=1,long zz=1) { a=0; Create(xx,yy,zz); } /// Delete the array virtual ~mglData() { if(id && a) delete []id; if(!link && a) delete []a; } - /// Get sizes inline mreal GetVal(long i, long j=0, long k=0) { return mgl_data_get_value(this,i,j,k);} inline void SetVal(mreal f, long i, long j=0, long k=0) { mgl_data_set_value(this,f,i,j,k); } + /// Get sizes inline long GetNx() const { return nx; } inline long GetNy() const { return ny; } inline long GetNz() const { return nz; } @@ -657,13 +657,13 @@ protected: // add for speeding up !!! inline mreal dvx(long i,long j=0,long k=0) const { register long i0=i+nx*(j+ny*k); - return i>0? (i0? (i0? (j0? (j0? (k0? (kSaveState(opt); long Num = isnan(r)?7:long(r+0.5); if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); return; } - mglData v(Num+2); - for(long i=0;i<=Num+1;i++) v.a[i] = gr->Min.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + mglData v(Num+2); v.Fill(gr->Min.c, gr->Max.c); mgl_contf_xy_val(gr,&v,x,y,z,sch,0); } //----------------------------------------------------------------------------- @@ -643,8 +642,7 @@ void mgl_contf(HMGL gr, HCDT z, const char *sch, const char *opt) float r = gr->SaveState(opt); long Num = isnan(r)?7:long(r+0.5); if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); return; } - mglData v(Num+2); - for(long i=0;i<=Num+1;i++) v.a[i] = gr->Min.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + mglData v(Num+2); v.Fill(gr->Min.c, gr->Max.c); mgl_contf_val(gr,&v,z,sch,0); } //----------------------------------------------------------------------------- @@ -1480,4 +1478,4 @@ void mgl_torus_(uintptr_t *gr, uintptr_t *r, uintptr_t *z, const char *pen, cons { char *s=new char[l+1]; memcpy(s,pen,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_torus(_GR_, _DA_(r), _DA_(z), s, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- diff --git a/src/plot.cpp b/src/plot.cpp index a22d8ed..bfd469d 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1265,12 +1265,12 @@ void mgl_error_exy(HMGL gr, HCDT x, HCDT y, HCDT ex, HCDT ey, const char *pen, c { if(mk) gr->mark_plot(gr->AddPnt(mglPoint(x->v(i,mx),y->v(i,my),zVal)), mk); - n1 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)+ey->v(i,m2), zVal)); - n2 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)-ey->v(i,m2), zVal)); + n1 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); gr->line_plot(n1,n2); gr->arrow_plot(n1,n2,'I'); gr->arrow_plot(n2,n1,'I'); - n1 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my), zVal)); - n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my), zVal)); + n1 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); gr->line_plot(n1,n2); gr->arrow_plot(n1,n2,'I'); gr->arrow_plot(n2,n1,'I'); if(sh) gr->NextColor(pal); } diff --git a/src/prim.cpp b/src/prim.cpp index cf082e8..7eaedcd 100644 --- a/src/prim.cpp +++ b/src/prim.cpp @@ -459,11 +459,16 @@ void mgl_dew_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, cons if(gr->MeshNum>1) { tx=(n-1)/(gr->MeshNum-1); ty=(m-1)/(gr->MeshNum-1); } if(tx<1) tx=1; if(ty<1) ty=1; - for(i=0,xm=0;iGetNz();i++) + for(k=0;kGetNz();k++) for(j=0;jvthr(i),ay->vthr(i)); + ym = sqrt(ax->v(i,j,k)*ax->v(i,j,k)+ay->v(i,j,k)*ay->v(i,j,k)); xm = xm>ym ? xm : ym; } +/* for(i=0,xm=0;iGetNz();i++) + { + ym = hypot(ax->vthr(i),ay->vthr(i)); + xm = xm>ym ? xm : ym; + }*/ xm = 1./MGL_FLT_EPS/(xm==0 ? 1:xm); mglPoint p,q; diff --git a/texinfo/CMakeLists.txt b/texinfo/CMakeLists.txt index 97c370a..2689808 100644 --- a/texinfo/CMakeLists.txt +++ b/texinfo/CMakeLists.txt @@ -2,7 +2,7 @@ # Warning!!!!! # new files and destination for html docs. -if(use_doc) +if(MGL_HAVE_DOC) add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/texinfo/png/all.png COMMAND LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/mgl ${CMAKE_BINARY_DIR}/examples/mgl_example COMMAND touch ${CMAKE_SOURCE_DIR}/texinfo/png/all.png @@ -57,4 +57,4 @@ if(use_doc) PATTERN "*/*.html" PATTERN "./mathgl*.info*" PATTERN "./mathgl*.pdf") -endif(use_doc) +endif(MGL_HAVE_DOC) diff --git a/texinfo/Makefile.am b/texinfo/Makefile.am index d35c1b3..a2eb88f 100644 --- a/texinfo/Makefile.am +++ b/texinfo/Makefile.am @@ -6,7 +6,7 @@ mathgl_ru.info mathgl_ru.info-1 mathgl_ru.info-2 mathgl_ru.info-3 mathgl_ru.info MAKEINFOHTML = texi2html TEXI2PDF = texi2pdf -AM_MAKEINFOHTMLFLAGS = --split=chapter +#AM_MAKEINFOHTMLFLAGS = --split=chapter AM_MAKEINFOFLAGS = --no-validate info_TEXINFOS = mathgl_en.texi diff --git a/texinfo/core_en.texi b/texinfo/core_en.texi index 3639426..f697b2e 100644 --- a/texinfo/core_en.texi +++ b/texinfo/core_en.texi @@ -545,7 +545,7 @@ Sets one of the predefined transformation formulas for curvilinear coordinate. P @deftypefnx {Method on @code{mglGraph}} @code{void} Ternary (@code{int} tern) @deftypefnx {C function} @code{void} mgl_set_ternary (@code{HMGL} gr, @code{int} tern) @end ifclear -The function sets to draws Ternary or Quaternary plot. Ternary plot is special plot for 3 dependent coordinates (components) @var{a}, @var{b}, @var{c} so that @var{a}+@var{b}+@var{c}=1. MathGL uses only 2 independent coordinates @var{a}=x and @var{b}=y since it is enough to plot everything. At this third coordinate z act as another parameter to produce contour lines, surfaces and so on. Correspondingly Quaternary plot is plot for 4 dependent coordinates @var{a}, @var{b}, @var{c} and @var{d} so that @var{a}+@var{b}+@var{c}+@var{d}=1. Use @code{Ternary(0)} for returning to usual axis. @sref{Ternary plot sample} +The function sets to draws Ternary or Quaternary plot. Ternary plot is special plot for 3 dependent coordinates (components) @var{a}, @var{b}, @var{c} so that @var{a}+@var{b}+@var{c}=1. MathGL uses only 2 independent coordinates @var{a}=x and @var{b}=y since it is enough to plot everything. At this third coordinate z act as another parameter to produce contour lines, surfaces and so on. Correspondingly Quaternary plot is plot for 4 dependent coordinates @var{a}, @var{b}, @var{c} and @var{d} so that @var{a}+@var{b}+@var{c}+@var{d}=1. Use @code{Ternary(0)} for returning to usual axis. @sref{Ternary axis} @end deftypefn @c ------------------------------------------------------------------ @@ -732,7 +732,7 @@ Puts further plotting in @var{ind}-th cell of column with @var{num} cells. The p @deftypefnx {C function} @code{void} mgl_gridplot (@code{HMGL} gr, @code{int} nx, @code{int} ny, @code{int} ind) @deftypefnx {C function} @code{void} mgl_gridplot_d (@code{HMGL} gr, @code{int} nx, @code{int} ny, @code{int} ind, @code{float} d) @end ifclear -Puts further plotting in @var{ind}-th cell of @var{nx}*@var{ny} grid. The position is relative to previous @ref{subplot} (or @ref{inplot} with @var{rel}=@code{false}). Parameter @var{d} set extra gap between cells. @sref{ColumnPlot sample} +Puts further plotting in @var{ind}-th cell of @var{nx}*@var{ny} grid. The position is relative to previous @ref{subplot} (or @ref{inplot} with @var{rel}=@code{false}). Parameter @var{d} set extra gap between cells. @end deftypefn @anchor{stickplot} @@ -1550,7 +1550,7 @@ Set the number of marks in the legend. By default 1 mark is used. These functions perform plotting of 1D data. 1D means that data depended from only 1 parameter like parametric curve @{x[i],y[i],z[i]@}, i=1...n. By default (if absent) values of @var{x}[i] are equidistantly distributed in axis range, and @var{z}[i]=@var{Min}.z. The plots are drawn for each row if one of the data is the matrix. By any case the sizes of 1st dimension @strong{must be equal} for all arrays @code{x.nx=y.nx=z.nx}. -String @var{pen} specifies the color and style of line and marks (see @ref{Line styles}). By default (@code{pen=""}) solid line with color from palette is used (see @ref{Palette and colors}). String @var{opt} contain command options (see @ref{Command options}). @sref{1D plot sample} +String @var{pen} specifies the color and style of line and marks (see @ref{Line styles}). By default (@code{pen=""}) solid line with color from palette is used (see @ref{Palette and colors}). String @var{opt} contain command options (see @ref{Command options}). @sref{1D samples} @anchor{plot} @deftypefn {MGL command} {} plot ydat ['stl'=''] @@ -1712,8 +1712,7 @@ These functions draw boxplot (also known as a box-and-whisker diagram) at points @deftypefnx {C function} @code{void} mgl_candle_yv (@code{HMGL} gr, @code{HCDT} v1, @code{HCDT} v2, @code{HCDT} y1, @code{HCDT} y2, @code{const char *}pen, @code{const char *}opt) @deftypefnx {C function} @code{void} mgl_candle_xyv (@code{HMGL} gr, @code{HCDT} x, @code{HCDT} v1, @code{HCDT} v2, @code{HCDT} y1, @code{HCDT} y2, @code{const char *}pen, @code{const char *}opt) @end ifclear -These functions draw candlestick chart at points @var{x}[i]. This is a combination of a line-chart and a bar-chart, in that each bar represents the range of price movement over a given time interval. Wire (or white) candle correspond to price growth @var{v1}[i]<@var{v2}[i], opposite case -- solid (or dark) candle. "Shadows" show the minimal @var{y1} and maximal @var{y2} prices. If @var{v2} is absent then it is determined as @var{v2}[i]=@var{v1}[i+1]. See also @ref{plot}, @ref{bars}, @ref{barwidth}. -@c TODO @sref{Candle sample} +These functions draw candlestick chart at points @var{x}[i]. This is a combination of a line-chart and a bar-chart, in that each bar represents the range of price movement over a given time interval. Wire (or white) candle correspond to price growth @var{v1}[i]<@var{v2}[i], opposite case -- solid (or dark) candle. "Shadows" show the minimal @var{y1} and maximal @var{y2} prices. If @var{v2} is absent then it is determined as @var{v2}[i]=@var{v1}[i+1]. See also @ref{plot}, @ref{bars}, @ref{barwidth}. @sref{Candle sample} @end deftypefn @@ -1824,7 +1823,7 @@ These functions draw surface which is result of curve @{@var{r}, @var{z}@} rotat @cindex Grid -These functions perform plotting of 2D data. 2D means that data depend from 2 independent parameters like matrix @math{f(x_i,y_j), i=1...n, j=1...m}. By default (if absent) values of @var{x}, @var{y} are equidistantly distributed in axis range. The plots are drawn for each z slice of the data. The minor dimensions of arrays @var{x}, @var{y}, @var{z} should be equal @code{x.nx=z.nx && y.nx=z.ny} or @code{x.nx=y.nx=z.nx && x.ny=y.ny=z.ny}. Arrays @var{x} and @var{y} can be vectors (not matrices as @var{z}). String @var{sch} sets the color scheme (see @ref{Color scheme}) for plot. Previous color scheme is used by default. String @var{opt} contain command options (see @ref{Command options}). @sref{2D plot sample} +These functions perform plotting of 2D data. 2D means that data depend from 2 independent parameters like matrix @math{f(x_i,y_j), i=1...n, j=1...m}. By default (if absent) values of @var{x}, @var{y} are equidistantly distributed in axis range. The plots are drawn for each z slice of the data. The minor dimensions of arrays @var{x}, @var{y}, @var{z} should be equal @code{x.nx=z.nx && y.nx=z.ny} or @code{x.nx=y.nx=z.nx && x.ny=y.ny=z.ny}. Arrays @var{x} and @var{y} can be vectors (not matrices as @var{z}). String @var{sch} sets the color scheme (see @ref{Color scheme}) for plot. Previous color scheme is used by default. String @var{opt} contain command options (see @ref{Command options}). @sref{2D samples} @anchor{surf} @deftypefn {MGL command} {} surf zdat ['sch'=''] @@ -2049,7 +2048,7 @@ The function draws grid lines for density plot of surface specified parametrical @cindex Cloud @cindex Beam -These functions perform plotting of 3D data. 3D means that data depend from 3 independent parameters like matrix @math{f(x_i,y_j,z_k), i=1...n, j=1...m, k=1...l}.By default (if absent) values of @var{x}, @var{y}, @var{z} are equidistantly distributed in axis range. The minor dimensions of arrays @var{x}, @var{y}, @var{z}, @var{a} should be equal @code{x.nx=a.nx && y.nx=a.ny && z.nz=a.nz} or @code{x.nx=y.nx=z.nx=a.nx && x.ny=y.ny=z.ny=a.ny && x.nz=y.nz=z.nz=a.nz}. Arrays @var{x}, @var{y} and @var{z} can be vectors (not matrices as @var{a}). String @var{sch} sets the color scheme (see @ref{Color scheme}) for plot. Previous color scheme is used by default. String @var{opt} contain command options (see @ref{Command options}). @sref{3D plot sample} +These functions perform plotting of 3D data. 3D means that data depend from 3 independent parameters like matrix @math{f(x_i,y_j,z_k), i=1...n, j=1...m, k=1...l}.By default (if absent) values of @var{x}, @var{y}, @var{z} are equidistantly distributed in axis range. The minor dimensions of arrays @var{x}, @var{y}, @var{z}, @var{a} should be equal @code{x.nx=a.nx && y.nx=a.ny && z.nz=a.nz} or @code{x.nx=y.nx=z.nx=a.nx && x.ny=y.ny=z.ny=a.ny && x.nz=y.nz=z.nz=a.nz}. Arrays @var{x}, @var{y} and @var{z} can be vectors (not matrices as @var{a}). String @var{sch} sets the color scheme (see @ref{Color scheme}) for plot. Previous color scheme is used by default. String @var{opt} contain command options (see @ref{Command options}). @sref{3D samples} @anchor{surf3} @deftypefn {MGL command} {} surf3 adat @code{val} ['sch'=''] @@ -2522,7 +2521,7 @@ gr->ContFX(c.Sum("x"),"BbcyrR",-1); gr->ContFY(c.Sum("y"),0,1); gr->ContFZ(c.Sum("z"),0,-1); @end example -will produce the following picture. See also @ref{ContFXYZ}, @ref{DensXYZ}, @ref{cont}, @ref{Data manipulation}. @sref{Cont projection sample} +will produce the following picture. See also @ref{ContFXYZ}, @ref{DensXYZ}, @ref{cont}, @ref{Data manipulation}. @sref{ContF projection sample} @end deftypefn @ifclear UDAV @@ -2582,7 +2581,7 @@ Draws command parametrical surface @{@samp{x(u,v)}, @samp{y(u,v)}, @samp{z(u,v)} @deftypefnx {C function} @code{void} mgl_triplot_xyz (@code{HMGL} gr, @code{HCDT} id, @code{HCDT} x, @code{HCDT} y, @code{HCDT} z, @code{const char *}sch, @code{const char *}opt) @deftypefnx {C function} @code{void} mgl_triplot_xyzc (@code{HMGL} gr, @code{HCDT} id, @code{HCDT} x, @code{HCDT} y, @code{HCDT} z, @code{HCDT} c, @code{const char *}sch, @code{const char *}opt) @end ifclear -The function draws the surface of triangles. Triangle vertexes are set by indexes @var{id} of data points @{@var{x}[i], @var{y}[i], @var{z}[i]@}. String @var{sch} sets the color scheme. Previous color scheme is used by default. If string contain @samp{#} then wire plot is produced. First dimensions of @var{id} must be 3 or greater. Arrays @var{x}, @var{y}, @var{z} must have equal sizes. Parameter @var{c} set the colors of triangles (if @var{id}.ny=@var{c}.nx) or colors of vertexes (if @var{x}.nx=@var{c}.nx). See also @ref{dots}, @ref{crust}, @ref{quadplot}. +The function draws the surface of triangles. Triangle vertexes are set by indexes @var{id} of data points @{@var{x}[i], @var{y}[i], @var{z}[i]@}. String @var{sch} sets the color scheme. Previous color scheme is used by default. If string contain @samp{#} then wire plot is produced. First dimensions of @var{id} must be 3 or greater. Arrays @var{x}, @var{y}, @var{z} must have equal sizes. Parameter @var{c} set the colors of triangles (if @var{id}.ny=@var{c}.nx) or colors of vertexes (if @var{x}.nx=@var{c}.nx). See also @ref{dots}, @ref{crust}, @ref{quadplot}. @sref{TriPlot and QuadPlot} @end deftypefn @anchor{tricont} @@ -2614,7 +2613,7 @@ The function draws contour lines for surface of triangles at @var{z}=@var{v}[k] @deftypefnx {C function} @code{void} mgl_quadplot_xyz (@code{HMGL} gr, @code{HCDT} id, @code{HCDT} x, @code{HCDT} y, @code{HCDT} z, @code{const char *}sch, @code{const char *}opt) @deftypefnx {C function} @code{void} mgl_quadplot_xyzc (@code{HMGL} gr, @code{HCDT} id, @code{HCDT} x, @code{HCDT} y, @code{HCDT} z, @code{HCDT} c, @code{const char *}sch, @code{const char *}opt) @end ifclear -The function draws the surface of quadrangles. Quadrangles vertexes are set by indexes @var{id} of data points @{@var{x}[i], @var{y}[i], @var{z}[i]@}. String @var{sch} sets the color scheme. Previous color scheme is used by default. If string contain @samp{#} then wire plot is produced. First dimensions of @var{id} must be 4 or greater. Arrays @var{x}, @var{y}, @var{z} must have equal sizes. Parameter @var{c} set the colors of quadrangles (if @var{id}.ny=@var{c}.nx) or colors of vertexes (if @var{x}.nx=@var{c}.nx). See also @ref{triplot}. +The function draws the surface of quadrangles. Quadrangles vertexes are set by indexes @var{id} of data points @{@var{x}[i], @var{y}[i], @var{z}[i]@}. String @var{sch} sets the color scheme. Previous color scheme is used by default. If string contain @samp{#} then wire plot is produced. First dimensions of @var{id} must be 4 or greater. Arrays @var{x}, @var{y}, @var{z} must have equal sizes. Parameter @var{c} set the colors of quadrangles (if @var{id}.ny=@var{c}.nx) or colors of vertexes (if @var{x}.nx=@var{c}.nx). See also @ref{triplot}. @sref{TriPlot and QuadPlot} @end deftypefn @anchor{dots} diff --git a/texinfo/ex_mgl_en.texi b/texinfo/ex_mgl_en.texi index 3e3bb50..c386549 100644 --- a/texinfo/ex_mgl_en.texi +++ b/texinfo/ex_mgl_en.texi @@ -641,7 +641,7 @@ It is an interesting result, is not it? @node Vector field visualization, Several light sources, Management of a point cutting, Hints @subsection Vector field visualization -Vector field visualization (especially in 3d case @code{vect3} or @code{vectc}) may look tangly -- there are too many overlapping lines. I may suggest 2 ways to solve this problem. The first one is to change @code{meshnum} for decreasing the number of hachures. The second way is to use the flow thread chart @code{Flow}. Unfortunately, I don't know any other methods to visualize 3d vector field. If you know any, e-mail me and I shall add it to MatGL. +Vector field visualization (especially in 3d case @code{vect3} or @code{vectc}) may look tangly -- there are too many overlapping lines. I may suggest 2 ways to solve this problem. The first one is to change @code{meshnum} for decreasing the number of hachures. The second way is to use the flow thread chart @code{Flow}. Unfortunately, I don't know any other methods to visualize 3d vector field. If you know any, e-mail me and I shall add it to MathGL. @c ------------------------------------------------------------------ @node Several light sources, CutMin and CutMax features, Vector field visualization, Hints diff --git a/texinfo/example_en.texi b/texinfo/example_en.texi index 1aaaf7e..9105856 100644 --- a/texinfo/example_en.texi +++ b/texinfo/example_en.texi @@ -11,8 +11,7 @@ This chapter contain information about basic and advanced MathGL, hints and samp * 1D samples:: * 2D samples:: * 3D samples:: -* Dual samples:: -* More samples:: +* Vector field samples:: * Hints:: * FAQ:: @end menu @@ -470,6 +469,7 @@ Now I show several non-obvious features of MathGL: several subplots in a single * Colorbars:: * Ternary axis:: * Text features:: +* Legend sample:: * Cutting sample:: @end menu @@ -775,7 +775,7 @@ int sample(mglGraph *gr) @end float @c ------------------------------------------------------------------ -@node Text features, Cutting sample, Ternary axis, Advanced usage +@node Text features, Legend sample, Ternary axis, Advanced usage @subsection Text features MathGL prints text by vector font. There are functions for manual specifying of text position (like @code{Puts}) and for its automatic selection (like @code{Label}, @code{Legend} and so on). MathGL prints text always in specified position even if it lies outside the bounding box. The default size of font is specified by functions @var{SetFontSize*} (see @ref{Font settings}). However, the actual size of output string depends on subplot size (depends on functions @code{SubPlot}, @code{InPlot}). The switching of the font style (italic, bold, wire and so on) can be done for the whole string (by function parameter) or inside the string. By default MathGL parses TeX-like commands for symbols and indexes (see @ref{Font styles}). @@ -824,7 +824,45 @@ int sample(mglGraph *gr) @end float @c ------------------------------------------------------------------ -@node Cutting sample, , Text features, Advanced usage +@node Legend sample, Cutting sample, Text features, Advanced usage +@subsection Legend sample + +Legend is one of standard ways to show plot annotations. Basically you need to connect the plot style (line style, marker and color) with some text. In MathGL, you can do it by 2 methods: manually using @code{AddLegend} function (see @ref{Legend}); or use @samp{legend} option (see @ref{Command options}), which will use last plot style. In both cases, legend entries will be added into internal accumulator, which later used for legend drawing itself. @code{ClearLegend} function allow you to remove all saved legend entries. + +There are 2 features. If plot style is empty then text will be printed without indent. If you want to plot the text with indent but without plot sample then you need to use space @samp{ } as plot style. Such style @samp{ } will draw a plot sample (line with marker(s)) which is invisible line (i.e. nothing) and print the text with indent as usual one. + +Function @code{Legend} draw legend on the plot. The position of the legend can be selected automatic or manually. You can change the size and style of text labels, as well as setup the plot sample. The sample code demonstrating legend features is: +@verbatim +int sample(mglGraph *gr) +{ + gr->AddLegend("sin(\\pi {x^2})","b"); + gr->AddLegend("sin(\\pi x)","g*"); + gr->AddLegend("sin(\\pi \\sqrt{x})","rd"); + gr->AddLegend("just text"," "); + gr->AddLegend("no indent for this",""); + + gr->SubPlot(2,2,0,""); gr->Title("Legend (default)"); + gr->Box(); gr->Legend(); + + gr->Legend(3,"A#"); + gr->Puts(mglPoint(0.75,0.65),"Absolute position","A"); + + gr->SubPlot(2,2,2,""); gr->Title("coloring"); gr->Box(); + gr->Legend(0,"r#"); gr->Legend(1,"Wb#"); gr->Legend(2,"ygr#"); + + gr->SubPlot(2,2,3,""); gr->Title("manual position"); + gr->Box(); gr->Legend(0.5,0.5); + return 0; +} +@end verbatim + +@float +@image{../png/legend, 11cm} +@caption{Example of legend} +@end float + +@c ------------------------------------------------------------------ +@node Cutting sample, , Legend sample, Advanced usage @subsection Cutting sample The last common thing which I want to show in this section is how one can cut off points from plot. There are 4 mechanism for that. @@ -957,314 +995,1729 @@ Creation of 2d- and 3d-arrays is mostly the same. But one should keep in mind th @end verbatim or by using @code{Modify()} function @verbatim - mglData z(30,40); - z.Modify("sin(pi*x)*cos(pi*y)"); + mglData z(30,40); + z.Modify("sin(pi*x)*cos(pi*y)"); +@end verbatim + +The only non-obvious thing here is using multidimensional arrays in C/C++, i.e. arrays defined like @code{float dat[40][30];}. Since, formally these elements @code{dat[i]} can address the memory in arbitrary place you should use the proper function to convert such arrays to @code{mglData} object. For C++ this is functions like @code{mglData::Set(float **dat, int N1, int N2);}. For C this is functions like @code{mgl_data_set_float2(HMDT d, const float **dat, int N1, int N2);}. At this, you should keep in mind that @code{nx=N2} and @code{ny=N1} after conversion. + +@c ------------------------------------------------------------------ +@node Linking array, Change data, Array creation, Data handling +@subsection Linking array + +Sometimes the data arrays are so large, that one couldn't' copy its values to another array (i.e. into mglData). In this case, he can define its own class derived from @code{mglDataA} (see @ref{User defined types}) or can use @code{Link} function. + +In last case, MathGL just save the link to an external data array, but not copy it. You should provide the existence of this data array for whole time during which MathGL can use it. Another point is that MathGL will automatically create new array if you'll try to modify data values by any of @code{mglData} functions. So, you should use only function with @code{const} modifier if you want still using link to the original data array. + +Creating the link is rather simple -- just the same as using @code{Set} function +@verbatim + double *a = new double[50]; + for(int i=0;i<50;i++) a[i] = sin(M_PI*i/49.); + + mglData y; + y.Link(a,50); +@end verbatim + +@c ------------------------------------------------------------------ +@node Change data, User defined types, Linking array, Data handling +@subsection Change data + +MathGL has functions for data processing: differentiating, integrating, smoothing and so on (for more detail, see @ref{Data processing}). Let us consider some examples. The simplest ones are integration and differentiation. The direction in which operation will be performed is specified by textual string, which may contain symbols @samp{x}, @samp{y} or @samp{z}. For example, the call of @code{Diff("x")} will differentiate data along @samp{x} direction; the call of @code{Integral("xy")} perform the double integration of data along @samp{x} and @samp{y} directions; the call of @code{Diff2("xyz")} will apply 3d Laplace operator to data and so on. Example of this operations on 2d array a=x*y is presented in code: +@verbatim +int sample(mglGraph *gr) +{ + gr->SetRanges(0,1,0,1,0,1); + mglData a(30,40); a.Modify("x*y"); + gr->SubPlot(2,2,0); gr->Rotate(60,40); + gr->Surf(a); gr->Box(); + gr->Puts(mglPoint(0.7,1,1.2),"a(x,y)"); + gr->SubPlot(2,2,1); gr->Rotate(60,40); + a.Diff("x"); gr->Surf(a); gr->Box(); + gr->Puts(mglPoint(0.7,1,1.2),"da/dx"); + gr->SubPlot(2,2,2); gr->Rotate(60,40); + a.Integral("xy"); gr->Surf(a); gr->Box(); + gr->Puts(mglPoint(0.7,1,1.2),"\\int da/dx dxdy"); + gr->SubPlot(2,2,3); gr->Rotate(60,40); + a.Diff2("y"); gr->Surf(a); gr->Box(); + gr->Puts(mglPoint(0.7,1,1.2),"\\int {d^2}a/dxdy dx"); + return 0; +} +@end verbatim + +@float +@image{../png/dat_diff, 11cm} +@caption{Example of data differentiation and integration} +@end float + +Data smoothing (function @code{Smooth()}) is more interesting and important. This function has single argument which define type of smoothing and its direction. Now 3 methods are supported: @samp{3} -- linear averaging by 3 points, @samp{5} -- linear averaging by 5 points, and default one -- quadratic averaging by 5 points. + +MathGL also have some amazing functions which is not so important for data processing as useful for data plotting. There are functions for finding envelope (useful for plotting rapidly oscillating data), for data sewing (useful to removing jumps on the phase), for data resizing (interpolation). Let me demonstrate it: +@verbatim +int sample(mglGraph *gr) +{ + gr->SubPlot(2,2,0,""); gr->Title("Envelop sample"); + mglData d1(1000); gr->Fill(d1,"exp(-8*x^2)*sin(10*pi*x)"); + gr->Axis(); gr->Plot(d1, "b"); + d1.Envelop('x'); gr->Plot(d1, "r"); + + gr->SubPlot(2,2,1,""); gr->Title("Smooth sample"); + mglData y0(30),y1,y2,y3; + gr->SetRanges(0,1,0,1); + gr->Fill(y0, "0.4*sin(pi*x) + 0.3*cos(1.5*pi*x) - 0.4*sin(2*pi*x)+0.5*rnd"); + + y1=y0; y1.Smooth("x3"); + y2=y0; y2.Smooth("x5"); + y3=y0; y3.Smooth("x"); + + gr->Plot(y0,"{m7}:s", "legend 'none'"); //gr->AddLegend("none","k"); + gr->Plot(y1,"r", "legend ''3' style'"); + gr->Plot(y2,"g", "legend ''5' style'"); + gr->Plot(y3,"b", "legend 'default'"); + gr->Legend(); gr->Box(); + + gr->SubPlot(2,2,2); gr->Title("Sew sample"); + mglData d2(100, 100); gr->Fill(d2, "mod((y^2-(1-x)^2)/2,0.1)"); + gr->Rotate(50, 60); gr->Light(true); gr->Alpha(true); + gr->Box(); gr->Surf(d2, "b"); + d2.Sew("xy", 0.1); gr->Surf(d2, "r"); + + gr->SubPlot(2,2,3); gr->Title("Resize sample (interpolation)"); + mglData x0(10), v0(10), x1, v1; + gr->Fill(x0,"rnd"); gr->Fill(v0,"rnd"); + x1 = x0.Resize(100); v1 = v0.Resize(100); + gr->Plot(x0,v0,"b+ "); gr->Plot(x1,v1,"r-"); + gr->Label(x0,v0,"%n"); + return 0; +} +@end verbatim + +@float +@image{../png/dat_extra, 11cm} +@caption{Example of data smoothing} +@end float + +Finally one can create new data arrays on base of the existing one: extract slice, row or column of data (@code{SubData()}), summarize along a direction(s) (@code{Sum()}), find distribution of data elements (@code{Hist()}) and so on. + +@c ------------------------------------------------------------------ +@node User defined types, , Change data, Data handling +@subsection User defined types + +@code{mglData} class have abstract predecessor class @code{mglDataA}. Exactly the pointers to @code{mglDataA} instances are used in all plotting functions and some of data processing functions. This was done for taking possibility to define yours own class, which will handle yours own data (for example, complex numbers, or differently organized data). And this new class will be almost the same as @code{mglData} for plotting purposes. + +However, the most of data processing functions will be slower as if you used @code{mglData} instance. This is more or less understandable -- I don't know how data in yours particular class will be organized, and couldn't optimize the these functions generally. + +There are few virtual functions which must be provided in derived classes. This functions give: +@itemize @bullet +@item +the sizes of the data (@code{GetNx}, @code{GetNy}, @code{GetNz}), +@item +give data value and numerical derivatives for selected cell (@code{v}, @code{dvx}, @code{dvy}, @code{dvz}), +@item +give maximal and minimal values (@code{Maximal}, @code{Minimal}) -- you can use provided functions (like @code{mgl_data_max} and @code{mgl_data_min}), but yours own realization can be more efficient, +@item +give access to all element as in single array (@code{vthr}) -- you need this only if you want using MathGL's data processing functions. +@end itemize + +Let me, for example define class @code{mglComplex} which will handle complex number and draw its amplitude or phase, depending on flag @var{use_abs}: +@verbatim +#include +#include +#define dual std::complex +class mglComplex : public mglDataA +{ +public: + long nx; ///< number of points in 1st dimensions ('x' dimension) + long ny; ///< number of points in 2nd dimensions ('y' dimension) + long nz; ///< number of points in 3d dimensions ('z' dimension) + dual *a; ///< data array + bool use_abs; ///< flag to use abs() or arg() + + inline mglComplex(long xx=1,long yy=1,long zz=1) + { a=0; use_abs=true; Create(xx,yy,zz); } + virtual ~mglComplex() { if(a) delete []a; } + + /// Get sizes + inline long GetNx() const { return nx; } + inline long GetNy() const { return ny; } + inline long GetNz() const { return nz; } + /// Create or recreate the array with specified size and fill it by zero + inline void Create(long mx,long my=1,long mz=1) + { nx=mx; ny=my; nz=mz; if(a) delete []a; + a = new dual[nx*ny*nz]; } + /// Get maximal value of the data + inline float Maximal() const { return mgl_data_max(this); } + /// Get minimal value of the data + inline float Minimal() const { return mgl_data_min(this); } + +protected: + inline mreal v(long i,long j=0,long k=0) const + { return use_abs ? abs(a[i+nx*(j+ny*k)]) : arg(a[i+nx*(j+ny*k)]); } + inline mreal vthr(long i) const + { return use_abs ? abs(a[i]) : arg(a[i]); } + inline mreal dvx(long i,long j=0,long k=0) const + { register long i0=i+nx*(j+ny*k); + std::complex res=i>0? (i res=j>0? (j res=k>0? (kSubPlot(2,2,0); + gr->Plot(y0); gr->Box(); +@end verbatim +Style of line is not specified in @code{Plot()} function. So MathGL uses the solid line with first color of palette (this is blue). Next subplot shows array @var{y1} with 2 rows: +@verbatim + gr->SubPlot(2,2,1); + mglData y1(50,2); + y1.Modify("sin(pi*2*x-pi)"); + y1.Modify("cos(pi*2*x-pi)/2",1); + gr->Plot(y1); gr->Box(); +@end verbatim +As previously I did not specify the style of lines. As a result, MathGL again uses solid line with next colors in palette (there are green and red). Now let us plot a circle on the same subplot. The circle is parametric curve @math{x=cos(\pi t), y=sin(\pi t)}. I will set the color of the circle (dark yellow, @samp{Y}) and put marks @samp{+} at point position: +@verbatim + mglData x(50); x.Modify("cos(pi*2*x-pi)"); + gr->Plot(x,y0,"Y+"); +@end verbatim +Note that solid line is used because I did not specify the type of line. The same picture can be achieved by @code{Plot()} and @code{SubData())} functions. Let us draw ellipse by orange dash line: +@verbatim + gr->Plot(y1.SubData(-1,0),y1.SubData(-1,1),"q|"); +@end verbatim + +Drawing in 3D space is mostly the same. Let us draw spiral with default line style. Now its color is 4-th color from palette (this is cyan): +@verbatim + gr->SubPlot(2,2,2); gr->Rotate(60,40); + mglData z(50); z.Modify("2*x-1"); + gr->Plot(x,y0,z); gr->Box(); +@end verbatim +Functions @code{Plot()} and @code{SubData())} make 3D curve plot but for single array. Use it to put circle marks on the previous plot: +@verbatim + mglData y2(10,3); y2.Modify("cos(pi*(2*x-1+y))"); + y2.Modify("2*x-1",2); + gr->Plot(y2.SubData(-1,0),y2.SubData(-1,1),y2.SubData(-1,2),"bo "); +@end verbatim +Note that line style is empty @samp{ } here. Usage of other 1D plotting functions looks similar: +@verbatim + gr->SubPlot(2,2,3); gr->Rotate(60,40); + gr->Bars(x,y0,z,"r"); gr->Box(); + return 0; +} +@end verbatim + +Surfaces @code{Surf()} and other 2D plots (@pxref{2D plotting}) are drown the same simpler as 1D one. The difference is that the string parameter specifies not the line style but the color scheme of the plot (see @ref{Color scheme}). Here I draw attention on 4 most interesting color schemes. There is gray scheme where color is changed from black to white (string @samp{kw}) or from white to black (string @samp{wk}). Another scheme is useful for accentuation of negative (by blue color) and positive (by red color) regions on plot (string @samp{"BbwrR"}). Last one is the popular ``jet'' scheme (string @samp{"BbcyrR"}). + +Now I shall show the example of a surface drawing. At first let us switch lightning on +@verbatim +int sample(mglGraph *gr) +{ + gr->Light(true); gr->Light(0,mglPoint(0,0,1)); +@end verbatim +and draw the surface, considering coordinates x,y to be uniformly distributed in interval @var{Min}*@var{Max} +@verbatim + mglData a0(50,40); + a0.Modify("0.6*sin(2*pi*x)*sin(3*pi*y)+0.4*cos(3*pi*(x*y))"); + gr->SubPlot(2,2,0); gr->Rotate(60,40); + gr->Surf(a0); gr->Box(); +@end verbatim +Color scheme was not specified. So previous color scheme is used. In this case it is default color scheme (``jet'') for the first plot. Next example is a sphere. The sphere is parametrically specified surface: +@verbatim + mglData x(50,40),y(50,40),z(50,40); + x.Modify("0.8*sin(2*pi*x)*sin(pi*y)"); + y.Modify("0.8*cos(2*pi*x)*sin(pi*y)"); + z.Modify("0.8*cos(pi*y)"); + gr->SubPlot(2,2,1); gr->Rotate(60,40); + gr->Surf(x,y,z,"BbwrR");gr->Box(); +@end verbatim +I set color scheme to @code{"BbwrR"} that corresponds to red top and blue bottom of the sphere. + +Surfaces will be plotted for each of slice of the data if @var{nz}>1. Next example draws surfaces for data arrays with @var{nz}=3: +@verbatim + mglData a1(50,40,3); + a1.Modify("0.6*sin(2*pi*x)*sin(3*pi*y)+0.4*cos(3*pi*(x*y))"); + a1.Modify("0.6*cos(2*pi*x)*cos(3*pi*y)+0.4*sin(3*pi*(x*y))",1); + a1.Modify("0.6*cos(2*pi*x)*cos(3*pi*y)+0.4*cos(3*pi*(x*y))",2); + gr->SubPlot(2,2,2); gr->Rotate(60,40); + gr->Alpha(true); + gr->Surf(a1); gr->Box(); +@end verbatim +Note, that it may entail a confusion. However, if one will use density plot then the picture will look better: +@verbatim + gr->SubPlot(2,2,3); gr->Rotate(60,40); + gr->Dens(a1); gr->Box(); + return 0; +} +@end verbatim + +Drawing of other 2D plots is analogous. The only peculiarity is the usage of flag @samp{#}. By default this flag switches on the drawing of a grid on plot (@code{Grid()} or @code{Mesh()} for plots in plain or in volume). However, for isosurfaces (including surfaces of rotation @code{Axial()}) this flag switches the face drawing off. Figure becomes wired. The following code gives example of flag @samp{#} using (compare with normal function drawing as in its description): +@verbatim +int sample(mglGraph *gr) +{ + gr->Alpha(true); gr->Light(true); gr->Light(0,mglPoint(0,0,1)); + mglData a(30,20); + a.Modify("0.6*sin(2*pi*x)*sin(3*pi*y) + 0.4*cos(3*pi*(x*y))"); + + gr->SubPlot(2,2,0); gr->Rotate(40,60); + gr->Surf(a,"BbcyrR#"); gr->Box(); + gr->SubPlot(2,2,1); gr->Rotate(40,60); + gr->Dens(a,"BbcyrR#"); gr->Box(); + gr->SubPlot(2,2,2); gr->Rotate(40,60); + gr->Cont(a,"BbcyrR#"); gr->Box(); + gr->SubPlot(2,2,3); gr->Rotate(40,60); + gr->Axial(a,"BbcyrR#"); gr->Box(); + return 0; +} +@end verbatim + +@c ------------------------------------------------------------------ +@node 1D samples, 2D samples, Data plotting, Examples +@section 1D samples + +This section is devoted to visualization of 1D data arrays. 1D means the data which depend on single index (parameter) like curve in parametric form @{x(i),y(i),z(i)@}, i=1...n. Most of samples will use the same data for plotting. So, I put its initialization in separate function +@verbatim +void mgls_prepare1d(mglData *y, mglData *y1=0, mglData *y2=0, mglData *x1=0, mglData *x2=0) +{ + register long i,n=50; + if(y) y->Create(n,3); + if(x1) x1->Create(n); if(x2) x2->Create(n); + if(y1) y1->Create(n); if(y2) y2->Create(n); + float xx; + for(i=0;ia[i] = 0.7*sin(2*M_PI*xx) + 0.5*cos(3*M_PI*xx) + 0.2*sin(M_PI*xx); + y->a[i+n] = sin(2*M_PI*xx); + y->a[i+2*n] = cos(2*M_PI*xx); + } + if(y1) y1->a[i] = 0.5+0.3*cos(2*M_PI*xx); + if(y2) y2->a[i] = 0.3*sin(2*M_PI*xx); + if(x1) x1->a[i] = xx*2-1; + if(x2) x2->a[i] = 0.05+0.03*cos(2*M_PI*xx); + } +} +@end verbatim +or using C functions +@verbatim +void mgls_prepare1d(HMDT y, HMDT y1=0, HMDT y2=0, HMDT x1=0, HMDT x2=0) +{ + register long i,n=50; + if(y) mgl_data_create(y,n,3,1); + if(x1) mgl_data_create(x1,n,1,1); + if(x2) mgl_data_create(x2,n,1,1); + if(y1) mgl_data_create(y1,n,1,1); + if(y2) mgl_data_create(y2,n,1,1); + float xx; + for(i=0;iSetOrigin(0,0,0); + gr->SubPlot(2,2,0,""); gr->Title("Plot plot (default)"); + gr->Box(); gr->Plot(y); + + gr->SubPlot(2,2,2,""); gr->Title("'!' style; 'rgb' palette"); + gr->Box(); gr->Plot(y,"o!rgb"); + + gr->SubPlot(2,2,3,""); gr->Title("just markers"); + gr->Box(); gr->Plot(y," +"); + + gr->SubPlot(2,2,1); gr->Title("3d variant"); + gr->Rotate(50,60); gr->Box(); + mglData yc(30), xc(30), z(30); z.Modify("2*x-1"); + yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); + gr->Plot(xc,yc,z,"rs"); + return 0; +} +@end verbatim + +@float +@image{../png/plot, 11cm} +@caption{Example of Plot()} +@end float + + +@c ------------------------------------------------------------------ +@node Radar sample, Step sample, Plot sample, 1D samples +@subsection Radar sample + +@code{Radar} plot is variant of @code{Plot} one, which make plot in polar coordinates and draw radial rays in point directions. If you just need a plot in polar coordinates then I recommend to use @ref{Curvilinear coordinates} or @code{Plot} in parabolic form with @code{x=r*cos(fi); y=r*sin(fi);}. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData yr(10,3); yr.Modify("0.4*sin(pi*(2*x+y))+0.1*rnd"); + gr->SubPlot(1,1,0,""); gr->Title("Radar plot (with grid, '\\#')"); + gr->Radar(yr,"#"); + return 0; +} +@end verbatim + +@float +@image{../png/radar, 11cm} +@caption{Example of Radar()} +@end float + +@c ------------------------------------------------------------------ +@node Step sample, Tens sample, Radar sample, 1D samples +@subsection Step sample + +@code{Step} plot data as stairs. It have the same options as @code{Plot}. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y; mgls_prepare1d(&y); gr->SetOrigin(0,0,0); + mglData yc(30), xc(30), z(30); z.Modify("2*x-1"); + yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); + + gr->SubPlot(2,2,0,""); gr->Title("Step plot (default)"); + gr->Box(); gr->Step(y); + + gr->SubPlot(2,2,1); gr->Title("3d variant"); gr->Rotate(50,60); + gr->Box(); gr->Step(xc,yc,z,"r"); + + gr->SubPlot(2,2,2,""); gr->Title("'!' style"); + gr->Box(); gr->Step(y,"s!rgb"); + return 0; +} +@end verbatim + +@float +@image{../png/step, 11cm} +@caption{Example of Step()} +@end float + +@c ------------------------------------------------------------------ +@node Tens sample, Area sample, Step sample, 1D samples +@subsection Tens sample + +@code{Tens} is variant of @code{Plot} with smooth coloring along the curves. At this, color is determined as for surfaces (see @ref{Color scheme}). The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y; mgls_prepare1d(&y); gr->SetOrigin(0,0,0); + gr->SubPlot(2,2,0,""); gr->Title("Tens plot (default)"); + gr->Box(); gr->Tens(y.SubData(-1,0), y.SubData(-1,1)); + + gr->SubPlot(2,2,2,""); gr->Title("' ' style"); + gr->Box(); gr->Tens(y.SubData(-1,0), y.SubData(-1,1),"o "); + + gr->SubPlot(2,2,1); gr->Title("3d variant"); gr->Rotate(50,60); gr->Box(); + mglData yc(30), xc(30), z(30); z.Modify("2*x-1"); + yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); + gr->Tens(xc,yc,z,z,"s"); + return 0; +} +@end verbatim + +@float +@image{../png/tens, 11cm} +@caption{Example of Tens()} +@end float + +@c ------------------------------------------------------------------ +@node Area sample, Region sample, Tens sample, 1D samples +@subsection Area sample + +@code{Area} fill the area between curve and axis plane. It support gradient filling if 2 colors per curve is specified. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y; mgls_prepare1d(&y); gr->SetOrigin(0,0,0); + gr->SubPlot(2,2,0,""); gr->Title("Area plot (default)"); + gr->Box(); gr->Area(y); + + gr->SubPlot(2,2,1,""); gr->Title("2 colors"); + gr->Box(); gr->Area(y,"cbgGyr"); + + gr->SubPlot(2,2,2,""); gr->Title("'!' style"); + gr->Box(); gr->Area(y,"!"); + + gr->SubPlot(2,2,3); gr->Title("3d variant"); + gr->Rotate(50,60); gr->Box(); + mglData yc(30), xc(30), z(30); z.Modify("2*x-1"); + yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); + gr->Area(xc,yc,z,"r"); + return 0; +} +@end verbatim + +@float +@image{../png/area, 11cm} +@caption{Example of Area()} +@end float + +@c ------------------------------------------------------------------ +@node Region sample, Stem sample, Area sample, 1D samples +@subsection Region sample + +@code{Region} fill the area between 2 curves. It support gradient filling if 2 colors per curve is specified. Also it can fill only the region y1SetOrigin(0,0,0); + gr->SubPlot(2,2,0,""); gr->Title("Region plot (default)"); + gr->Box(); gr->Region(y1,y2); gr->Plot(y1,"k2"); gr->Plot(y2,"k2"); + + gr->SubPlot(2,2,1,""); gr->Title("2 colors"); + gr->Box(); gr->Region(y1,y2,"yr"); gr->Plot(y1,"k2"); gr->Plot(y2,"k2"); + + gr->SubPlot(2,2,2,""); gr->Title("'!' style"); + gr->Box(); gr->Region(y1,y2,"!"); gr->Plot(y1,"k2"); gr->Plot(y2,"k2"); + + gr->SubPlot(2,2,3,""); gr->Title("'i' style"); + gr->Box(); gr->Region(y1,y2,"ir"); gr->Plot(y1,"k2"); gr->Plot(y2,"k2"); + return 0; +} +@end verbatim + +@float +@image{../png/region, 11cm} +@caption{Example of Region()} +@end float + +@c ------------------------------------------------------------------ +@node Stem sample, Bars sample, Region sample, 1D samples +@subsection Stem sample + +@code{Stem} draw vertical bars. It is most attractive if markers are drawn too. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y; mgls_prepare1d(&y); gr->SetOrigin(0,0,0); + mglData yc(30), xc(30), z(30); z.Modify("2*x-1"); + yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); + gr->SubPlot(2,2,0,""); gr->Title("Stem plot (default)"); + gr->Box(); gr->Stem(y); + + gr->SubPlot(2,2,1); gr->Title("3d variant"); gr->Rotate(50,60); + gr->Box(); gr->Stem(xc,yc,z,"rx"); + + gr->SubPlot(2,2,2,""); gr->Title("'!' style"); + gr->Box(); gr->Stem(y,"o!rgb"); + return 0; +} +@end verbatim + +@float +@image{../png/stem, 11cm} +@caption{Example of Stem()} +@end float + +@c ------------------------------------------------------------------ +@node Bars sample, Barh sample, Stem sample, 1D samples +@subsection Bars sample + +@code{Bars} draw vertical bars. It have a lot of options: bar-above-bar (@samp{a} style), fall like (@samp{f} style), 2 colors for positive and negative values, wired bars (@samp{#} style), 3D variant. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData ys(10,3); ys.Modify("0.8*sin(pi*(2*x+y/2))+0.2*rnd"); + gr->SetOrigin(0,0,0); + gr->SubPlot(3,2,0,""); gr->Title("Bars plot (default)"); + gr->Box(); gr->Bars(ys); + + gr->SubPlot(3,2,1,""); gr->Title("2 colors"); + gr->Box(); gr->Bars(ys,"cbgGyr"); + + gr->SubPlot(3,2,4,""); gr->Title("'\\#' style"); + gr->Box(); gr->Bars(ys,"#"); + + gr->SubPlot(3,2,5); gr->Title("3d variant"); + gr->Rotate(50,60); gr->Box(); + mglData yc(30), xc(30), z(30); z.Modify("2*x-1"); + yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); + gr->Bars(xc,yc,z,"r"); + + gr->SetRanges(-1,1,-3,3); + gr->SubPlot(3,2,2,""); gr->Title("'a' style"); + gr->Box(); gr->Bars(ys,"a"); + + gr->SubPlot(3,2,3,""); gr->Title("'f' style"); + gr->Box(); gr->Bars(ys,"f"); + return 0; +} +@end verbatim + +@float +@image{../png/bars, 11cm} +@caption{Example of Bars()} +@end float + +@c ------------------------------------------------------------------ +@node Barh sample, Chart sample, Bars sample, 1D samples +@subsection Barh sample + +@code{Barh} is the similar to @code{Bars} but draw horizontal bars. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData ys(10,3); ys.Modify("0.8*sin(pi*(2*x+y/2))+0.2*rnd"); + gr->SetOrigin(0,0,0); + gr->SubPlot(2,2,0,""); gr->Title("Barh plot (default)"); + gr->Box(); gr->Barh(ys); + + gr->SubPlot(2,2,1,""); gr->Title("2 colors"); + gr->Box(); gr->Barh(ys,"cbgGyr"); + + gr->SetRanges(-3,3,-1,1); + gr->SubPlot(2,2,2,""); gr->Title("'a' style"); + gr->Box(); gr->Barh(ys,"a"); + + gr->SubPlot(2,2,3,""); gr->Title("'f' style"); + gr->Box(); gr->Barh(ys,"f"); + return 0; +} +@end verbatim + +@float +@image{../png/barh, 11cm} +@caption{Example of Barh()} +@end float + +@c ------------------------------------------------------------------ +@node Chart sample, BoxPlot sample, Barh sample, 1D samples +@subsection Chart sample + +@code{Chart} draw colored boxes with width proportional to data values. Use @samp{ } for empty box. Plot looks most attractive in polar coordinates -- well known pie chart. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData ch(7,2); for(int i=0;i<7*2;i++) ch.a[i]=mgl_rnd()+0.1; + gr->SubPlot(2,2,0); gr->Title("Chart plot (default)"); + gr->Light(true); gr->Rotate(50,60); gr->Box(); gr->Chart(ch); + + gr->SubPlot(2,2,1); gr->Title("'\\#' style"); + gr->Rotate(50,60); gr->Box(); gr->Chart(ch,"#"); + + gr->SubPlot(2,2,2); gr->Title("Pie chart; ' ' color"); + gr->SetFunc("(y+1)/2*cos(pi*x)","(y+1)/2*sin(pi*x)",""); + gr->Rotate(50,60); gr->Box(); gr->Chart(ch,"bgr cmy#"); + + gr->SubPlot(2,2,3); gr->Title("Ring chart; ' ' color"); + gr->SetFunc("(y+2)/3*cos(pi*x)","(y+2)/3*sin(pi*x)",""); + gr->Rotate(50,60); gr->Box(); gr->Chart(ch,"bgr cmy#"); + return 0; +} +@end verbatim + +@float +@image{../png/chart, 11cm} +@caption{Example of Chart()} +@end float + +@c ------------------------------------------------------------------ +@node BoxPlot sample, Candle sample, Chart sample, 1D samples +@subsection BoxPlot sample + +@code{BoxPlot} draw box-and-whisker diagram. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a(10,7); a.Modify("(2*rnd-1)^3/2"); + gr->SubPlot(1,1,0,""); gr->Title("Boxplot plot"); + gr->Box(); gr->BoxPlot(a); + return 0; +} +@end verbatim + +@float +@image{../png/boxplot, 11cm} +@caption{Example of BoxPlot()} +@end float + +@c ------------------------------------------------------------------ +@node Candle sample, Error sample, BoxPlot sample, 1D samples +@subsection Candle sample + +@code{Candle} draw candlestick chart. This is a combination of a line-chart and a bar-chart, in that each bar represents the range of price movement over a given time interval. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y(30); gr->Fill(y,"sin(2*pi*x)^2"); + mglData y1(30); gr->Fill(y1,"v/2",y); + mglData y2(30); gr->Fill(y2,"(1+v)/2",y); + gr->SubPlot(1,1,0,""); gr->Title("Candle plot (default)"); + gr->SetRange('y',0,1); gr->Box(); gr->Candle(y,y1,y2); + return 0; +} +@end verbatim + +@float +@image{../png/candle, 11cm} +@caption{Example of Candle()} +@end float + +@c ------------------------------------------------------------------ +@node Error sample, Mark sample, Candle sample, 1D samples +@subsection Error sample + +@code{Error} draw error boxes around the points. You can draw default boxes or semi-transparent symbol (like marker, see @ref{Line styles}). Also you can set individual color for each box. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y; mgls_prepare1d(&y); + mglData x0(10), y0(10), ex0(10), ey0(10); + float x; + for(int i=0;i<10;i++) + { + x = i/9.; + x0.a[i] = 2*x-1 + 0.1*mgl_rnd()-0.05; + y0.a[i] = 0.7*sin(2*M_PI*x)+0.5*cos(3*M_PI*x)+0.2*sin(M_PI*x)+0.2*mgl_rnd()-0.1; + ey0.a[i]=0.2; ex0.a[i]=0.1; + } + + gr->SubPlot(2,2,0,""); gr->Title("Error plot (default)"); + gr->Box(); gr->Plot(y.SubData(-1,0)); gr->Error(x0,y0,ex0,ey0,"ko"); + + gr->SubPlot(2,2,1,""); gr->Title("'!' style; no e_x"); + gr->Box(); gr->Plot(y.SubData(-1,0)); gr->Error(x0,y0,ey0,"o!rgb"); + + gr->SubPlot(2,2,2,""); gr->Title("'\\@' style"); + gr->Box(); gr->Plot(y.SubData(-1,0)); gr->Error(x0,y0,ex0,ey0,"@","alpha 0.5"); + + gr->SubPlot(2,2,3); gr->Title("3d variant"); gr->Rotate(50,60); + for(int i=0;i<10;i++) + gr->Error(mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1,2*mgl_rnd()-1), + mglPoint(0.2,0.2,0.2),"bo"); + gr->Axis(); + return 0; +} +@end verbatim + +@float +@image{../png/error, 11cm} +@caption{Example of Error()} +@end float + +@c ------------------------------------------------------------------ +@node Mark sample, TextMark sample, Error sample, 1D samples +@subsection Mark sample + +@code{Mark} draw markers at points. It is mostly the same as @code{Plot} but marker size can be variable. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y,y1; mgls_prepare1d(&y,&y1); + gr->SubPlot(1,1,0,""); gr->Title("Mark plot (default)"); + gr->Box(); gr->Mark(y,y1,"s"); + return 0; +} +@end verbatim + +@float +@image{../png/mark, 11cm} +@caption{Example of Mark()} +@end float + +@c ------------------------------------------------------------------ +@node TextMark sample, Label sample, Mark sample, 1D samples +@subsection TextMark sample + +@code{TextMark} like @code{Mark} but draw text instead of markers. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y,y1; mgls_prepare1d(&y,&y1); + gr->SubPlot(1,1,0,""); gr->Title("TextMark plot (default)"); + gr->Box(); gr->TextMark(y,y1,"\\gamma","r"); + return 0; +} +@end verbatim + +@float +@image{../png/textmark, 11cm} +@caption{Example of TextMark()} +@end float + +@c ------------------------------------------------------------------ +@node Label sample, Tube sample, TextMark sample, 1D samples +@subsection Label sample + +@code{Label} print text at data points. The string may contain @samp{%x}, @samp{%y}, @samp{%z} for x-, y-, z-coordinates of points, @samp{%n} for point index. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData ys(10); ys.Modify("0.8*sin(pi*2*x)+0.2*rnd"); + gr->SubPlot(1,1,0,""); gr->Title("Label plot"); + gr->Box(); gr->Plot(ys," *"); gr->Label(ys,"y=%y"); + return 0; +} +@end verbatim + +@float +@image{../png/label, 11cm} +@caption{Example of Label()} +@end float + + +@c ------------------------------------------------------------------ +@node Tube sample, Tape sample, Label sample, 1D samples +@subsection Tube sample + +@code{Tube} draw tube with variable radius. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y,y1,y2; mgls_prepare1d(&y,&y1,&y2); y1/=20; + gr->SubPlot(2,2,0,""); gr->Title("Tube plot (default)"); + gr->Light(true); gr->Box(); gr->Tube(y,0.05); + + gr->SubPlot(2,2,1,""); gr->Title("variable radius"); + gr->Box(); gr->Tube(y,y1); + + gr->SubPlot(2,2,2,""); gr->Title("'\\#' style"); + gr->Box(); gr->Tube(y,0.05,"#"); + mglData yc(50), xc(50), z(50); z.Modify("2*x-1"); + yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); + + gr->SubPlot(2,2,3); gr->Title("3d variant"); gr->Rotate(50,60); + gr->Box(); gr->Tube(xc,yc,z,y2,"r"); + return 0; +} +@end verbatim + +@float +@image{../png/tube, 11cm} +@caption{Example of Tube()} +@end float + + +@c ------------------------------------------------------------------ +@node Tape sample, Torus sample, Tube sample, 1D samples +@subsection Tape sample + +@code{Tape} draw tapes which rotate around the curve as normal and binormal. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y; mgls_prepare1d(&y); + mglData xc(50), yc(50), z(50); + yc.Modify("sin(pi*(2*x-1))"); + xc.Modify("cos(pi*2*x-pi)"); z.Fill(-1,1); + gr->SubPlot(2,2,0,""); gr->Title("Tape plot (default)"); + gr->Box(); gr->Tape(y); gr->Plot(y,"k"); + + gr->SubPlot(2,2,1); gr->Title("3d variant, 2 colors"); + gr->Rotate(50,60); gr->Light(true); + gr->Box(); gr->Plot(xc,yc,z,"k"); gr->Tape(xc,yc,z,"rg"); + + gr->SubPlot(2,2,2); gr->Title("3d variant, x only"); gr->Rotate(50,60); + gr->Box(); gr->Plot(xc,yc,z,"k"); + gr->Tape(xc,yc,z,"xr"); gr->Tape(xc,yc,z,"xr#"); + + gr->SubPlot(2,2,3); gr->Title("3d variant, z only"); gr->Rotate(50,60); + gr->Box(); gr->Plot(xc,yc,z,"k"); + gr->Tape(xc,yc,z,"zg"); gr->Tape(xc,yc,z,"zg#"); + return 0; +} +@end verbatim + +@float +@image{../png/tape, 11cm} +@caption{Example of Tape()} +@end float + + +@c ------------------------------------------------------------------ +@node Torus sample, , Tape sample, 1D samples +@subsection Torus sample + +@code{Torus} draw surface of the curve rotation. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData y1,y2; mgls_prepare1d(0,&y1,&y2); + gr->SubPlot(2,2,0); gr->Title("Torus plot (default)"); + gr->Light(true); gr->Rotate(50,60); gr->Box(); gr->Torus(y1,y2); + if(mini) return; + + gr->SubPlot(2,2,1); gr->Title("'x' style"); gr->Rotate(50,60); + gr->Box(); gr->Torus(y1,y2,"x"); + + gr->SubPlot(2,2,2); gr->Title("'z' style"); gr->Rotate(50,60); + gr->Box(); gr->Torus(y1,y2,"z"); + + gr->SubPlot(2,2,3); gr->Title("'\\#' style"); gr->Rotate(50,60); + gr->Box(); gr->Torus(y1,y2,"#"); + return 0; +} +@end verbatim + +@float +@image{../png/torus, 11cm} +@caption{Example of Torus()} +@end float + + +@c ------------------------------------------------------------------ +@node 2D samples, 3D samples, 1D samples, Examples +@section 2D samples + +This section is devoted to visualization of 2D data arrays. 2D means the data which depend on 2 indexes (parameters) like matrix z(i,j)=z(x(i),y(j)), i=1...n, j=1...m or in parametric form @{x(i,j),y(i,j),z(i,j)@}. Most of samples will use the same data for plotting. So, I put its initialization in separate function +@verbatim +void mgls_prepare2d(mglData *a, mglData *b=0, mglData *v=0) +{ + register long i,j,n=50,m=40,i0; + if(a) a->Create(n,m); if(b) b->Create(n,m); + if(v) { v->Create(9); v->Fill(-1,1); } + float x,y; + for(i=0;ia[i0] = 0.6*sin(2*M_PI*x)*sin(3*M_PI*y)+0.4*cos(3*M_PI*x*y); + if(b) b->a[i0] = 0.6*cos(2*M_PI*x)*cos(3*M_PI*y)+0.4*cos(3*M_PI*x*y); + } +} +@end verbatim +or using C functions +@verbatim +void mgls_prepare2d(HMDT a, HMDT b=0, HMDT v=0) +{ + register long i,j,n=50,m=40,i0; + if(a) mgl_data_create(a,n,m,1); + if(b) mgl_data_create(b,n,m,1); + if(v) { mgl_data_create(v,9,1,1); mgl_data_fill(v,-1,1,'x'); } + float x,y; + for(i=0;iSubPlot(2,2,0); gr->Title("Surf plot (default)"); + gr->Light(true); gr->Rotate(50,60); gr->Box(); gr->Surf(a); + + gr->SubPlot(2,2,1); gr->Title("'\\#' style; meshnum 10"); + gr->Rotate(50,60); gr->Box(); gr->Surf(a,"#","meshnum 10"); + + gr->SubPlot(2,2,2); gr->Title("'|' style"); + gr->Rotate(50,60); gr->Box(); gr->Surf(a,"|"); + + gr->SubPlot(2,2,3); gr->Title("parametric form"); + mglData x(50,40),y(50,40),z(50,40); + gr->Fill(x,"0.8*sin(pi*x)*sin(pi*(y+1)/2)"); + gr->Fill(y,"0.8*cos(pi*x)*sin(pi*(y+1)/2)"); + gr->Fill(z,"0.8*cos(pi*(y+1)/2)"); + gr->Rotate(50,60); gr->Box(); gr->Surf(x,y,z,"BbwrR"); + return 0; +} +@end verbatim + +@float +@image{../png/surf, 11cm} +@caption{Example of Surf()} +@end float + +@c ------------------------------------------------------------------ +@node SurfC sample, SurfA sample, Surf sample, 2D samples +@subsection SurfC sample + +@code{SurfC} is similar to @code{Surf} but its coloring is determined by another data. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a,b; mgls_prepare2d(&a,&b); + gr->Title("SurfC plot"); gr->Rotate(50,60); + gr->Light(true); gr->Box(); gr->SurfC(a,b); + return 0; +} +@end verbatim + +@float +@image{../png/surfc, 11cm} +@caption{Example of SurfC()} +@end float + +@c ------------------------------------------------------------------ +@node SurfA sample, Mesh sample, SurfC sample, 2D samples +@subsection SurfA sample + +@code{SurfA} is similar to @code{Surf} but its transparency is determined by another data. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a,b; mgls_prepare2d(&a,&b); + gr->Title("SurfA plot"); gr->Rotate(50,60); + gr->Alpha(true); gr->Light(true); + gr->Box(); gr->SurfA(a,b); + return 0; +} +@end verbatim + +@float +@image{../png/surfa, 11cm} +@caption{Example of SurfA()} +@end float + + +@c ------------------------------------------------------------------ +@node Mesh sample, Fall sample, SurfA sample, 2D samples +@subsection Mesh sample + +@code{Mesh} draw wired surface. You can use @code{SetMeshNum} for changing number of lines to be drawn. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a; mgls_prepare2d(&a); + gr->Title("Mesh plot"); gr->Rotate(50,60); + gr->Box(); gr->Mesh(a); + return 0; +} +@end verbatim + +@float +@image{../png/mesh, 11cm} +@caption{Example of Mesh()} +@end float + +@c ------------------------------------------------------------------ +@node Fall sample, Belt sample, Mesh sample, 2D samples +@subsection Fall sample + +@code{Fall} draw waterfall surface. You can use @code{SetMeshNum} for changing number of lines to be drawn. Also you can use @samp{x} style for drawing lines in other direction. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a; mgls_prepare2d(&a); + gr->Title("Fall plot"); gr->Rotate(50,60); + gr->Box(); gr->Fall(a); + return 0; +} +@end verbatim + +@float +@image{../png/fall, 11cm} +@caption{Example of Fall()} +@end float + +@c ------------------------------------------------------------------ +@node Belt sample, Boxs sample, Fall sample, 2D samples +@subsection Belt sample + +@code{Belt} draw surface by belts. You can use @samp{x} style for drawing lines in other direction. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a; mgls_prepare2d(&a); + gr->Title("Belt plot"); gr->Rotate(50,60); + gr->Box(); gr->Belt(a); + return 0; +} +@end verbatim + +@float +@image{../png/belt, 11cm} +@caption{Example of Belt()} +@end float + +@c ------------------------------------------------------------------ +@node Boxs sample, Tile sample, Fall sample, 2D samples +@subsection Boxs sample + +@code{Boxs} draw surface by boxes. You can use @samp{#} for drawing wire plot. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a; mgls_prepare2d(&a); + gr->SetOrigin(0,0,0); gr->Light(true); + gr->SubPlot(2,2,0); gr->Title("Boxs plot (default)"); + gr->Rotate(40,60); gr->Box(); gr->Boxs(a); + + gr->SubPlot(2,2,1); gr->Title("'\\@' style"); + gr->Rotate(50,60); gr->Box(); gr->Boxs(a,"@"); + + gr->SubPlot(2,2,2); gr->Title("'\\#' style"); + gr->Rotate(50,60); gr->Box(); gr->Boxs(a,"#"); + + gr->SubPlot(2,2,3); gr->Title("compare with Tile"); + gr->Rotate(50,60); gr->Box(); gr->Tile(a); + return 0; +} +@end verbatim + +@float +@image{../png/boxs, 11cm} +@caption{Example of Boxs()} +@end float + +@c ------------------------------------------------------------------ +@node Tile sample, TileS sample, Boxs sample, 2D samples +@subsection Tile sample + +@code{Tile} draw surface by tiles. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a; mgls_prepare2d(&a); + gr->Title("Tile plot"); + gr->Rotate(40,60); gr->Box(); gr->Tile(a); + return 0; +} +@end verbatim + +@float +@image{../png/tile, 11cm} +@caption{Example of Tile()} +@end float + +@c ------------------------------------------------------------------ +@node TileS sample, Dens sample, Tile sample, 2D samples +@subsection TileS sample + +@code{TileS} is similar to @code{Tile} but tile sizes is determined by another data. This allows one to simulate transparency of the plot. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a,b; mgls_prepare2d(&a,&b); + gr->SubPlot(1,1,0,""); gr->Title("TileS plot"); + gr->Box(); gr->TileS(a,b); + return 0; +} +@end verbatim + +@float +@image{../png/tiles, 11cm} +@caption{Example of TileS()} +@end float + + +@c ------------------------------------------------------------------ +@node Dens sample, Cont sample, TileS sample, 2D samples +@subsection Dens sample + +@code{Dens} draw density plot for surface. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a,a1(30,40,3); mgls_prepare2d(&a); + gr->Fill(a1,"0.6*sin(2*pi*x+pi*(z+1)/2)*sin(3*pi*y+pi*z) + 0.4*cos(3*pi*(x*y)+pi*(z+1)^2/2)"); + gr->SubPlot(2,2,0,""); gr->Title("Dens plot (default)"); + gr->Box(); gr->Dens(a); + + gr->SubPlot(2,2,1); gr->Title("3d variant"); + gr->Rotate(50,60); gr->Box(); gr->Dens(a); + + gr->SubPlot(2,2,2,""); gr->Title("'\\#' style; meshnum 10"); + gr->Box(); gr->Dens(a,"#","meshnum 10"); + + gr->SubPlot(2,2,3); gr->Title("several slices"); + gr->Rotate(50,60); gr->Box(); gr->Dens(a1); + return 0; +} +@end verbatim + +@float +@image{../png/dens, 11cm} +@caption{Example of Dens()} +@end float + +@c ------------------------------------------------------------------ +@node Cont sample, ContF sample, Dens sample, 2D samples +@subsection Cont sample + +@code{Cont} draw contour lines for surface. You can select automatic (default) or manual levels for contours, print contour labels, draw it on the surface (default) or at plane (as @code{Dens}). The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a,v(5); mgls_prepare2d(&a); v.a[0]=-0.5; v.a[1]=-0.15; v.a[2]=0; v.a[3]=0.15; v.a[4]=0.5; + gr->SubPlot(2,2,0); gr->Title("Cont plot (default)"); + gr->Rotate(50,60); gr->Box(); gr->Cont(a); + + gr->SubPlot(2,2,1); gr->Title("manual levels"); + gr->Rotate(50,60); gr->Box(); gr->Cont(v,a); + + gr->SubPlot(2,2,2); gr->Title("'\\_' style"); + gr->Rotate(50,60); gr->Box(); gr->Cont(a,"_"); + + gr->SubPlot(2,2,3,""); gr->Title("'t' style"); + gr->Box(); gr->Cont(a,"t"); + return 0; +} +@end verbatim + +@float +@image{../png/cont, 11cm} +@caption{Example of Cont()} +@end float + +@c ------------------------------------------------------------------ +@node ContF sample, ContD sample, Cont sample, 2D samples +@subsection ContF sample + +@code{ContF} draw filled contours. You can select automatic (default) or manual levels for contours. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a,v(5),a1(30,40,3); mgls_prepare2d(&a); v.a[0]=-0.5; + v.a[1]=-0.15; v.a[2]=0; v.a[3]=0.15; v.a[4]=0.5; + gr->SubPlot(2,2,0); gr->Title("ContF plot (default)"); + gr->Rotate(50,60); gr->Box(); gr->ContF(a); + + gr->SubPlot(2,2,1); gr->Title("manual levels"); + gr->Rotate(50,60); gr->Box(); gr->ContF(v,a); + + gr->SubPlot(2,2,2); gr->Title("'\\_' style"); + gr->Rotate(50,60); gr->Box(); gr->ContF(a,"_"); + + gr->Fill(a1,"0.6*sin(2*pi*x+pi*(z+1)/2)*sin(3*pi*y+pi*z) + 0.4*cos(3*pi*(x*y)+pi*(z+1)^2/2)"); + gr->SubPlot(2,2,3); gr->Title("several slices"); + gr->Rotate(50,60); gr->Box(); gr->ContF(a1); + return 0; +} @end verbatim -The only non-obvious thing here is using multidimensional arrays in C/C++, i.e. arrays defined like @code{float dat[40][30];}. Since, formally these elements @code{dat[i]} can address the memory in arbitrary place you should use the proper function to convert such arrays to @code{mglData} object. For C++ this is functions like @code{mglData::Set(float **dat, int N1, int N2);}. For C this is functions like @code{mgl_data_set_float2(HMDT d, const float **dat, int N1, int N2);}. At this, you should keep in mind that @code{nx=N2} and @code{ny=N1} after conversion. +@float +@image{../png/contf, 11cm} +@caption{Example of ContF()} +@end float @c ------------------------------------------------------------------ -@node Linking array, Change data, Array creation, Data handling -@subsection Linking array +@node ContD sample, ContV sample, ContF sample, 2D samples +@subsection ContD sample + +@code{ContD} is similar to @code{ContF} but with manual contour colors. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData a,v(5),a1(30,40,3); mgls_prepare2d(&a); v.a[0]=-0.5; + v.a[1]=-0.15; v.a[2]=0; v.a[3]=0.15; v.a[4]=0.5; + gr->SubPlot(2,2,0); gr->Title("ContD plot (default)"); + gr->Rotate(50,60); gr->Box(); gr->ContD(a); -Sometimes the data arrays are so large, that one don't need to copy its values to another array (i.e. into mglData). + gr->SubPlot(2,2,1); gr->Title("manual levels"); + gr->Rotate(50,60); gr->Box(); gr->ContD(v,a); + gr->SubPlot(2,2,2); gr->Title("'\\_' style"); + gr->Rotate(50,60); gr->Box(); gr->ContD(a,"_"); + gr->Fill(a1,"0.6*sin(2*pi*x+pi*(z+1)/2)*sin(3*pi*y+pi*z) + 0.4*cos(3*pi*(x*y)+pi*(z+1)^2/2)"); + gr->SubPlot(2,2,3); gr->Title("several slices"); + gr->Rotate(50,60); gr->Box(); gr->ContD(a1); + return 0; +} +@end verbatim +@float +@image{../png/contd, 11cm} +@caption{Example of ContD()} +@end float @c ------------------------------------------------------------------ -@node Change data, User defined types, Linking array, Data handling -@subsection Change data +@node ContV sample, Axial sample, ContD sample, 2D samples +@subsection ContV sample -MathGL has functions for data processing: differentiating, integrating, smoothing and so on (for more detail, @pxref{Data processing}). Let us consider some examples. The simplest ones are integration and differentiation. The direction in which operation will be performed is specified by textual string, which may contain symbols @samp{x}, @samp{y} or @samp{z}. For example, the call of @code{Diff("x")} will differentiate data along @samp{x} direction; the call of @code{Integral("xy")} perform the double integration of data along @samp{x} and @samp{y} directions; the call of @code{Diff2("xyz")} will apply 3d Laplace operator to data and so on. Example of this operations on 2d array a=x*y is presented in code: +@code{ContV} draw vertical cylinders (belts) at contour lines. The sample code is: @verbatim - int sample(mglGraph *gr) - { - mglData a(30,40); a.Modify("x*y"); - gr->Axis(mglPoint(0,0,0),mglPoint(1,1,1)); - gr->SubPlot(2,2,0); gr->Rotate(60,40); - gr->Surf(a); gr->Box(); - gr->Puts(mglPoint(0.7,1,1.2),"a(x,y)"); - gr->SubPlot(2,2,1); gr->Rotate(60,40); - a.Diff("x"); gr->Surf(a); gr->Box(); - gr->Puts(mglPoint(0.7,1,1.2),"da/dx"); - gr->SubPlot(2,2,2); gr->Rotate(60,40); - a.Integral("xy"); gr->Surf(a); gr->Box(); - gr->Puts(mglPoint(0.7,1,1.2),"\\int da/dx dxdy"); - gr->SubPlot(2,2,3); gr->Rotate(60,40); - a.Diff2("y"); gr->Surf(a); gr->Box(); - gr->Puts(mglPoint(0.7,1,1.2),"\\int {d^2}a/dxdy dx"); - return 0; - } +int sample(mglGraph *gr) +{ + mglData a,v(5); mgls_prepare2d(&a); v.a[0]=-0.5; + v.a[1]=-0.15; v.a[2]=0; v.a[3]=0.15; v.a[4]=0.5; + gr->SubPlot(2,2,0); gr->Title("ContV plot (default)"); + gr->Rotate(50,60); gr->Box(); gr->ContV(a); + + gr->SubPlot(2,2,1); gr->Title("manual levels"); + gr->Rotate(50,60); gr->Box(); gr->ContV(v,a); + + gr->SubPlot(2,2,2); gr->Title("'\\_' style"); + gr->Rotate(50,60); gr->Box(); gr->ContV(a,"_"); + + gr->SubPlot(2,2,3); gr->Title("ContV and ContF"); + gr->Rotate(50,60); gr->Box(); gr->Light(true); + gr->ContV(a); gr->ContF(a); gr->Cont(a,"k"); + return 0; +} @end verbatim @float -@image{../png/sample6, 7cm} -@caption{Example of data differentiation and integration} +@image{../png/contv, 11cm} +@caption{Example of ContV()} @end float -Data smoothing (function @code{Smooth()}) is more interesting and important. This function has 2 main arguments: type of smoothing and its direction. Now 4 methods are supported: @code{SMOOTH_NONE} does nothing for delta=0 or approaches data to zero with the step delta, @code{SMOOTH_LINE_3} linear averaging by 3 points, @code{SMOOTH_LINE_5} linear averaging by 5 points, @code{SMOOTH_QUAD_5} quadratic averaging by 5 points. Let me demonstrate it for 1d case: +@c ------------------------------------------------------------------ +@node Axial sample, , ContV sample, 2D samples +@subsection Axial sample + +@code{Axial} draw surfaces of rotation for contour lines. You can draw wire surfaces (@samp{#} style) or ones rotated in other directions (@samp{x}, @samp{z} styles). The sample code is: @verbatim - int sample(mglGraph *gr) - { - mglData y0(30),y1,y2,y3; - y0.Modify("0.4*sin(2*pi*x)+0.3*cos(3*pi*x)-0.4*sin(4*pi*x)+0.2*rnd"); - - y1=y0; y1.Smooth(SMOOTH_LINE_3); - y2=y0; y2.Smooth(SMOOTH_LINE_5); - y3=y0; y3.Smooth(SMOOTH_QUAD_5); - - gr->Plot(y0,"k"); gr->AddLegend("NONE","k"); - gr->Plot(y1,"r"); gr->AddLegend("LINE_3","r"); - gr->Plot(y2,"g"); gr->AddLegend("LINE_5","g"); - gr->Plot(y3,"b"); gr->AddLegend("QUAD_5","b"); - gr->Legend(); gr->Box(); - return 0; - } +int sample(mglGraph *gr) +{ + mglData a; mgls_prepare2d(&a); + gr->SubPlot(2,2,0); gr->Title("Axial plot (default)"); + gr->Light(true); gr->Alpha(true); gr->Rotate(50,60); + gr->Box(); gr->Axial(a); + + gr->SubPlot(2,2,1); gr->Title("'x' style"); gr->Rotate(50,60); + gr->Box(); gr->Axial(a,"x"); + + gr->SubPlot(2,2,2); gr->Title("'z' style"); gr->Rotate(50,60); + gr->Box(); gr->Axial(a,"z"); + + gr->SubPlot(2,2,3); gr->Title("'\\#' style"); gr->Rotate(50,60); + gr->Box(); gr->Axial(a,"#"); + return 0; +} @end verbatim @float -@image{../png/sample7, 7cm} -@caption{Example of data smoothing} +@image{../png/axial, 11cm} +@caption{Example of Axial()} @end float -Finally one can create new data arrays on base of the existing one: extract slice, row or column of data (@code{SubData()}), summarize along some of direction(s) (@code{Sum()}), find distribution of data elements (@code{Hist()}). Note, that all these functions are not thread-safe because they use static internal variable for output array. In particular, the using of several of them in arguments of the same function will lead to unpredictable result. @c ------------------------------------------------------------------ -@node Data plotting, 1D samples, Data handling, Examples -@section Data plotting +@node 3D samples, Vector field samples, 2D samples, Examples +@section 3D samples -Let me now show how to plot the data. MathGL generally has 2 types of plotting functions. Simple variant requires a single data array for plotting, other data (coordinates) are considered uniformly distributed in interval @var{Min}*@var{Max}. Second variant requires data arrays for all coordinates. It allows one to plot rather complex multivalent curves and surfaces (in case of parametric dependencies). Argument setting to default values allows one to plot data in standard form. Manual arguments setting gives possibility for fine tuning of colors, positions and view of graphics. Note, that the call of drawing function adds something to picture but does not clear the previous plots (as it does in Matlab). Another difference from Matlab is that all setup (like transparency, lightning, axis borders and so on) must be specified @strong{before} plotting functions. +This section is devoted to visualization of 3D data arrays. 3D means the data which depend on 3 indexes (parameters) like tensor a(i,j,k)=a(x(i),y(j),x(k)), i=1...n, j=1...m, k=1...l or in parametric form @{x(i,j,k),y(i,j,k),z(i,j,k),a(i,j,k)@}. Most of samples will use the same data for plotting. So, I put its initialization in separate function +@verbatim +void mgls_prepare3d(mglData *a, mglData *b=0) +{ + register long i,j,k,n=61,m=50,l=40,i0; + if(a) a->Create(n,m,l); if(b) b->Create(n,m,l); + float x,y,z; + for(i=0;ia[i0] = -2*(x*x + y*y + z*z*z*z - z*z - 0.1); + if(b) b->a[i0] = 1-2*tanh((x+y)*(x+y)); + } +} +@end verbatim +or using C functions +@verbatim +void mgls_prepare3d(HMDT a, HMDT b=0) +{ + register long i,j,k,n=61,m=50,l=40,i0; + if(a) mgl_data_create(a,n,m,l); + if(b) mgl_data_create(b,n,m,l); + float x,y,z; + for(i=0;iSubPlot(2,2,0); - gr->Plot(y0); gr->Box(); -@end verbatim -Style of line is not specified in @code{Plot()} function. So MathGL uses the solid line with first color of palette (this is blue). Next subplot shows array @var{y1} with 2 rows: -@verbatim - gr->SubPlot(2,2,1); - mglData y1(50,2); - y1.Modify("sin(pi*2*x-pi)"); - y1.Modify("cos(pi*2*x-pi)/2",1); - gr->Plot(y1); gr->Box(); -@end verbatim -As previously I did not specify the style of lines. As a result, MathGL again uses solid line with next colors in palette (there are green and red). Now let us plot a circle on the same subplot. The circle is parametric curve @math{x=cos(\pi t), y=sin(\pi t)}. I will set the color of the circle (dark yellow, @samp{Y}) and put marks @samp{+} at point position: -@verbatim - mglData x(50); x.Modify("cos(pi*2*x-pi)"); - gr->Plot(x,y0,"Y+"); -@end verbatim -Note that solid line is used because I did not specify the type of line. The same picture can be achieved by @code{Plot()} and @code{SubData())} functions. Let us draw ellipse by orange dash line: +@code{Surf3} is one of most suitable (for my opinion) functions to visualize 3D data. It draw the isosurface(s) -- surface(s) of constant amplitude (3D analogue of contour lines). You can draw wired isosurfaces if specify @samp{#} style. The sample code is: @verbatim - gr->Plot(y1.SubData(-1,0),y1.SubData(-1,1),"q|"); +int sample(mglGraph *gr) +{ + mglData c; mgls_prepare3d(&c); + gr->Title("Surf3 plot"); gr->Rotate(50,60); + gr->Light(true); gr->Alpha(true); + gr->Box(); gr->Surf3(c); + return 0; +} @end verbatim -Drawing in 3D space is mostly the same. Let us draw spiral with default line style. Now its color is 4-th color from palette (this is cyan): -@verbatim - gr->SubPlot(2,2,2); gr->Rotate(60,40); - mglData z(50); z.Modify("2*x-1"); - gr->Plot(x,y0,z); gr->Box(); -@end verbatim -Functions @code{Plot()} and @code{SubData())} make 3D curve plot but for single array. Use it to put circle marks on the previous plot: -@verbatim - mglData y2(10,3); y2.Modify("cos(pi*(2*x-1+y))"); - y2.Modify("2*x-1",2); - gr->Plot(y2.SubData(-1,0),y2.SubData(-1,1),y2.SubData(-1,2),"bo "); -@end verbatim -Note that line style is empty @samp{ } here. Usage of other 1D plotting functions looks similar: +@float +@image{../png/surf3, 11cm} +@caption{Example of Surf3()} +@end float + +@c ------------------------------------------------------------------ +@node Surf3C sample, Surf3A sample, Surf3 sample, 3D samples +@subsection Surf3C sample + +@code{Surf3C} is similar to @code{Surf3} but its coloring is determined by another data. The sample code is: @verbatim - gr->SubPlot(2,2,3); gr->Rotate(60,40); - gr->Bars(x,y0,z,"r"); gr->Box(); - return 0; - } +int sample(mglGraph *gr) +{ + mglData c,d; mgls_prepare3d(&c,&d); + gr->Title("Surf3C plot"); gr->Rotate(50,60); + gr->Light(true); gr->Alpha(true); + gr->Box(); gr->Surf3C(c,d); + return 0; +} @end verbatim @float -@image{../png/sample8, 7cm} -@caption{Example of 1D data plot} +@image{../png/surf3c, 11cm} +@caption{Example of Surf3C()} @end float @c ------------------------------------------------------------------ -@node Plots for 2D data, Plots for 3D data, Plots for 1D data, Data plotting -@subsection Plots for 2D data +@node Surf3A sample, Cloud sample, Surf3C sample, 3D samples +@subsection Surf3A sample -Surfaces @code{Surf()} and other 2D plots (@pxref{2D plotting}) are drown the same simpler as 1D one. The difference is that the string parameter specifies not by line style but by the color scheme of the plot (@pxref{Color scheme}). Here I draw attention on 4 most interesting color schemes. There is gray scheme where color is changed from black to white (string @samp{kw}) or from white to black (string @samp{wk}). Another scheme is useful for accentuation of negative (by blue color) and positive (by red color) regions on plot (string @samp{"BbwrR"}). Last one is the popular ``jet'' scheme (string @samp{"BbcyrR"}). - -Now I shall show the example of a surface drawing. At first let us switch lightning on -@verbatim - int sample(mglGraph *gr) - { - gr->Light(true); gr->Light(0,mglPoint(0,0,1)); -@end verbatim -and draw the surface, considering coordinates x,y to be uniformly distributed in interval @var{Min}*@var{Max} +@code{Surf3A} is similar to @code{Surf3} but its transparency is determined by another data. The sample code is: @verbatim - mglData a0(50,40); - a0.Modify("0.6*sin(2*pi*x)*sin(3*pi*y)+0.4*cos(3*pi*(x*y))"); - gr->SubPlot(2,2,0); gr->Rotate(60,40); - gr->Surf(a0); gr->Box(); -@end verbatim -Color scheme was not specified. So previous color scheme is used. In this case it is default color scheme (``jet'') for the first plot. Next example is a sphere. The sphere is parametrically specified surface: -@verbatim - mglData x(50,40),y(50,40),z(50,40); - x.Modify("0.8*sin(2*pi*x)*sin(pi*y)"); - y.Modify("0.8*cos(2*pi*x)*sin(pi*y)"); - z.Modify("0.8*cos(pi*y)"); - gr->SubPlot(2,2,1); gr->Rotate(60,40); - gr->Surf(x,y,z,"BbwrR");gr->Box(); +int sample(mglGraph *gr) +{ + mglData c,d; mgls_prepare3d(&c,&d); + gr->Title("Surf3A plot"); gr->Rotate(50,60); + gr->Light(true); gr->Alpha(true); + gr->Box(); gr->Surf3A(c,d); + return 0; +} @end verbatim -I set color scheme to @code{"BbwrR"} that corresponds to red top and blue bottom of the sphere. -Surfaces will be plotted for each of slice of the data if @var{nz}>1. Next example draws surfaces for data arrays with @var{nz}=3: -@verbatim - mglData a1(50,40,3); - a1.Modify("0.6*sin(2*pi*x)*sin(3*pi*y)+0.4*cos(3*pi*(x*y))"); - a1.Modify("0.6*cos(2*pi*x)*cos(3*pi*y)+0.4*sin(3*pi*(x*y))",1); - a1.Modify("0.6*cos(2*pi*x)*cos(3*pi*y)+0.4*cos(3*pi*(x*y))",2); - gr->SubPlot(2,2,2); gr->Rotate(60,40); - gr->Alpha(true); - gr->Surf(a1); gr->Box(); -@end verbatim -Note, that it may entail a confusion. However, if one will use density plot then the picture will look better: +@float +@image{../png/surf3a, 11cm} +@caption{Example of Surf3A()} +@end float + +@c ------------------------------------------------------------------ +@node Cloud sample, Dens3 sample, Surf3A sample, 3D samples +@subsection Cloud sample + +@code{Cloud} draw cloud-like object which is less transparent for higher data values. Similar plot can be created using many (about 10-20) @code{Surf3A(a,a)} isosurfaces. The sample code is: @verbatim - gr->SubPlot(2,2,3); gr->Rotate(60,40); - gr->Dens(a1); gr->Box(); - return 0; - } +int sample(mglGraph *gr) +{ + mglData c; mgls_prepare3d(&c); + gr->SubPlot(2,2,0); gr->Title("Cloud plot"); + gr->Rotate(50,60); gr->Alpha(true); + gr->Box(); gr->Cloud(c,"wyrRk"); + + gr->SubPlot(2,2,1); gr->Title("'!' style"); + gr->Rotate(50,60); gr->Box(); gr->Cloud(c,"!wyrRk"); + + gr->SubPlot(2,2,2); gr->Title("'.' style"); + gr->Rotate(50,60); gr->Box(); gr->Cloud(c,".wyrRk"); + + gr->SubPlot(2,2,3); gr->Title("meshnum 10"); + gr->Rotate(50,60); gr->Box(); gr->Cloud(c,"wyrRk","meshnum 10"); + return 0; +} @end verbatim -Note, that the previous color scheme is used in last plots because there are no direct specification of the one. @float -@image{../png/sample9, 7cm} -@caption{Example of surface plot for 2D data} +@image{../png/cloud, 11cm} +@caption{Example of Cloud()} @end float -Drawing of other 2D plots is analogous. The only peculiarity is the usage of flag @samp{#}. By default this flag switches on the drawing of a grid on plot (@code{Grid()} or @code{Mesh()} for plots in plain or in volume). However, for isosurfaces (including surfaces of rotation @code{Axial()}) this flag switches the face drawing off. Figure becomes wired. The following code gives example of flag @samp{#} using (compare with normal function drawing as in its description): -@verbatim - int sample(mglGraph *gr) - { - gr->Alpha(true); gr->Light(true); gr->Light(0,mglPoint(0,0,1)); - mglData a(30,20); - a.Modify("0.6*sin(2*pi*x)*sin(3*pi*y) + 0.4*cos(3*pi*(x*y))"); +@c ------------------------------------------------------------------ +@node Dens3 sample, Cont3 sample, Cloud sample, 3D samples +@subsection Dens3 sample - gr->SubPlot(2,2,0); gr->Rotate(40,60); - gr->Surf(a,"BbcyrR#"); gr->Box(); - gr->SubPlot(2,2,1); gr->Rotate(40,60); - gr->Dens(a,"BbcyrR#"); gr->Box(); - gr->SubPlot(2,2,2); gr->Rotate(40,60); - gr->Cont(a,"BbcyrR#"); gr->Box(); - gr->SubPlot(2,2,3); gr->Rotate(40,60); - gr->Axial(a,"BbcyrR#"); gr->Box(); - return 0; - } +@code{Dens3} draw just usual density plot but at slices of 3D data. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData c; mgls_prepare3d(&c); + gr->Title("Dens3 sample"); gr->Rotate(50,60); + gr->Alpha(true); gr->SetAlphaDef(0.7); + gr->SetOrigin(0,0,0); gr->Axis("_xyz"); gr->Box(); + gr->Dens3(c,"x"); gr->Dens3(c); gr->Dens3(c,"z"); + return 0; +} @end verbatim @float -@image{../png/samplea, 7cm} -@caption{Example of 2D data plot with color scheme contained @samp{#} symbol} +@image{../png/densa, 11cm} +@caption{Example of Dens3()} @end float @c ------------------------------------------------------------------ -@node Plots for 3D data, Surface transparency, Plots for 2D data, Data plotting -@subsection Plots for 3D data +@node Cont3 sample, ContF3 sample, Dens3 sample, 3D samples +@subsection Cont3 sample -Drawing procedures for 3D plot looks similarly to 1D and 2D plots described above. There are 3 general types of 3D plots (@pxref{3D plotting}): (i) plots on slices or on projections, (ii) isosurfaces, (iii) cloud-like plots. Plots on slice are clear enough -- one specifies a slice (as its index or as coordinate value) and MathGL draws contour lines or density plot on slice plane. Isosurface gives more information. Isosurface is 3D analogue of the contour line @code{Cont()}. It shows the region where data array values exceed specified isosurface level. Plot becomes more informative if one adds transparency, lightning or sets color scheme depending on coordinates. Generalization of isosurface is the cloud-like plot. For this plot the darker color and less transparent regions correspond to higher values of data. Contrary, the regions with low values are transparent. For plotting of the phase of fields (or beams or pulses) one can use isosurface which transparency depends on the other data array (see function @code{Surf3A()}). As example of 3D data plots let us draw the Gaussian beam diffraction in space. Beam propagates along @var{x} axis: +@code{Cont3} draw just usual contour lines but at slices of 3D data. The sample code is: @verbatim - int sample(mglGraph *gr) - { - gr->Alpha(true); gr->Light(true); - gr->Light(0,mglPoint(0,0,1)); - mglData a(30,30,30),b(30,30,30); - a.Modify("exp(-16*((z-0.5)^2+(y-0.5)^2)/(1+4*x^2))"); - b.Modify("16*((z-0.5)^2+(y-0.5)^2)*(x)/(1+4*x^2)"); - gr->CAxis(0,1); - - gr->SubPlot(2,2,0); gr->Rotate(40,60); - gr->Surf3(a,"wgk"); gr->Box(); - gr->SubPlot(2,2,1); gr->Rotate(40,60); - gr->DensA(a); gr->Box(); gr->Axis(); - gr->SubPlot(2,2,2); gr->Rotate(40,60); - gr->CloudQ(a); gr->Box(); - gr->SubPlot(2,2,3); gr->Rotate(40,60); - gr->Surf3A(b,a,"q");gr->Box(); - return 0; - } +int sample(mglGraph *gr) +{ + mglData c; mgls_prepare3d(&c); + gr->Title("Cont3 sample"); gr->Rotate(50,60); + gr->Alpha(true); gr->SetAlphaDef(0.7); + gr->SetOrigin(0,0,0); gr->Axis("_xyz"); gr->Box(); + gr->Cont3(c,"x"); gr->Cont3(c); gr->Cont3(c,"z"); + return 0; +} @end verbatim @float -@image{../png/sampleb, 7cm} -@caption{Example of Gaussian beam diffraction (3D data)} +@image{../png/conta, 11cm} +@caption{Example of Cont3()} @end float - @c ------------------------------------------------------------------ -@node Surface transparency, , Plots for 3D data, Data plotting -@subsection Surface transparency - -MathGL library has advanced features for setting and handling the surface transparency. The simplest way to add transparency is the using of function @code{Alpha()}. As a result, all further surfaces (and isosurfaces, density plots and so on) become transparent. However, their look can be additionally improved. +@node ContF3 sample, Dens projection sample, Cont3 sample, 3D samples +@subsection ContF3 sample -First, the selected surface will be non-transparent if one sets the flag @code{Transparent} before the surface drawing and sets it off after the drawing. +@code{ContF3} draw just usual filled contours but at slices of 3D data. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData c; mgls_prepare3d(&c); + gr->Title("ContF3 sample"); gr->Rotate(50,60); + gr->Alpha(true); gr->SetAlphaDef(0.7); + gr->SetOrigin(0,0,0); gr->Axis("_xyz"); gr->Box(); + gr->ContF3(c,"x"); gr->ContF3(c); gr->ContF3(c,"z"); + gr->Cont3(c,"kx"); gr->Cont3(c,"k"); gr->Cont3(c,"kz"); + return 0; +} +@end verbatim -Second, the value of transparency can be different from surface to surface. To do it just change the value of @code{AlphaDef} before the drawing of the selected surface. If its value is close to 0 then the surface becomes more and more transparent. Contrary, if its value is close to 1 then the surface becomes practically non-transparent. This is some analogue of @code{Transparent=true}. +@float +@image{../png/contfa, 11cm} +@caption{Example of ContF3()} +@end float -Third feature is the changing of the way how the light goes through overlapped surfaces. The variable @code{TranspType} defines it. By default the usual transparency is used (@code{TranspType=0}) -- surfaces below is less visible than the upper ones. A ``glass-like'' transparency (@code{TranspType=1}) has a different look when the surface just decreases the background light (the surfaces are commutable in this case). +@c ------------------------------------------------------------------ +@node Dens projection sample, Cont projection sample, ContF3 sample, 3D samples +@subsection Dens projection sample -A ``neon-like'' transparency (@code{TranspType=2}) has more interesting look. In this case a surface is the light source (like a lamp on the dark background) and just adds some intensity to the color. At this, the library sets automatically the black color for the background and changes the default line color to white. +@code{Dens[XYZ]} draw density plot on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData c; mgls_prepare3d(&c); + gr->Title("Dens[XYZ] sample"); gr->Rotate(50,60); + gr->Box(); gr->DensX(c.Sum("x"),0,-1); + gr->DensY(c.Sum("y"),0,1); gr->DensZ(c.Sum("z"),0,-1); + return 0; +} +@end verbatim -As example I shall show the variant of plot from @ref{Plots for 2D data} (grid drawing is disabled) for different types of transparency. @float -@image{../png/type0, 7cm} -@caption{Example of @code{TranspType=0}.} +@image{../png/dens_xyz, 11cm} +@caption{Example of DensX(), DensY(), DensZ()} @end float + +@c ------------------------------------------------------------------ +@node Cont projection sample, ContF projection sample, Dens projection sample, 3D samples +@subsection Cont projection sample + +@code{Cont[XYZ]} draw contour lines on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData c; mgls_prepare3d(&c); + gr->Title("Cont[XYZ] sample"); gr->Rotate(50,60); + gr->Box(); gr->ContX(c.Sum("x"),"",-1); + gr->ContY(c.Sum("y"),"",1); gr->ContZ(c.Sum("z"),"",-1); + return 0; +} +@end verbatim + @float -@image{../png/type1, 7cm} -@caption{Example of @code{TranspType=1}.} +@image{../png/cont_xyz, 11cm} +@caption{Example of ContX(), ContY(), ContZ()} @end float + +@c ------------------------------------------------------------------ +@node ContF projection sample, TriPlot and QuadPlot, Cont projection sample, 3D samples +@subsection ContF projection sample + +@code{Dens[XYZ]} draw filled contours on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + mglData c; mgls_prepare3d(&c); + gr->Title("Cont[XYZ] sample"); gr->Rotate(50,60); + gr->Box(); gr->ContFX(c.Sum("x"),"",-1); + gr->ContFY(c.Sum("y"),"",1); gr->ContFZ(c.Sum("z"),"",-1); + return 0; +} +@end verbatim + @float -@image{../png/type2, 7cm} -@caption{Example of @code{TranspType=2}.} +@image{../png/contf_xyz, 11cm} +@caption{Example of ContFX(), ContFY(), ContFZ()} @end float +@c ------------------------------------------------------------------ +@node TriPlot and QuadPlot, Axial sample, ContF projection sample, 3D samples +@subsection TriPlot and QuadPlot +@code{TriPlot} and @code{QuadPlot} draw set of triangles (or quadrangles for @code{QuadPlot}) for irregular data arrays. Note, that you have to provide not only vertexes, but also the indexes of triangles or quadrangles. I.e. perform triangulation by some other library. The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + float q[] = {0,1,2,3, 4,5,6,7, 0,2,4,6, 1,3,5,7, 0,4,1,5, 2,6,3,7}; + float xc[] = {-1,1,-1,1,-1,1,-1,1}, yc[] = {-1,-1,1,1,-1,-1,1,1}, zc[] = {-1,-1,-1,-1,1,1,1,1}; + mglData qq(6,4,q), xx(8,xc), yy(8,yc), zz(8,zc); + gr->Light(true); //gr->Alpha(true); + gr->SubPlot(2,1,0); gr->Title("QuadPlot sample"); gr->Rotate(50,60); + gr->QuadPlot(qq,xx,yy,zz,"yr"); + gr->QuadPlot(qq,xx,yy,zz,"k#"); + + float t[] = {0,1,2, 0,1,3, 0,2,3, 1,2,3}; + float xt[] = {-1,1,0,0}, yt[] = {-1,-1,1,0}, zt[] = {-1,-1,-1,1}; + mglData tt(4,3,t), uu(4,xt), vv(4,yt), ww(4,zt); + gr->SubPlot(2,1,1); gr->Title("TriPlot sample"); gr->Rotate(50,60); + gr->TriPlot(tt,uu,vv,ww,"b"); + gr->TriPlot(tt,uu,vv,ww,"k#"); + return 0; +} +@end verbatim -@c ------------------------------------------------------------------ -@node 1D samples, 2D samples, Data plotting, Examples -@section 1D samples +@float +@image{../png/triplot, 11cm} +@caption{Example of TriPlot() and QuadPlot()} +@end float @c ------------------------------------------------------------------ -@node 2D samples, 3D samples, 1D samples, Examples -@section 2D samples +@node Dots sample, , TriPlot and QuadPlot, 3D samples +@subsection Dots sample -@c ------------------------------------------------------------------ -@node 3D samples, Dual samples, 2D samples, Examples -@section 3D samples +@code{Dots} is another way to draw irregular points. @code{Dots} use color scheme for coloring (see @ref{Color scheme}). The sample code is: +@verbatim +int sample(mglGraph *gr) +{ + int i, n=1000; + mglData x(n),y(n),z(n); + for(i=0;iTitle("Dots sample"); gr->Rotate(50,60); + gr->Box(); gr->Dots(x,y,z); + return 0; +} +@end verbatim -@c ------------------------------------------------------------------ -@node Dual samples, More samples, 3D samples, Examples -@section Dual samples +@float +@image{../png/dots, 11cm} +@caption{Example of Dots()} +@end float @c ------------------------------------------------------------------ -@node More samples, Hints, Dual samples, Examples -@section More samples +@node Vector field samples, Hints, 3D samples, Examples +@section Vector field samples + +Vector field visualization (especially in 3d case) may look tangly -- there are too many overlapping lines. I may suggest 2 ways to solve this problem. The first one is to change @code{MeshNum} for decreasing the number of hachures. The second way is to use the flow thread chart @code{Flow}. Unfortunately, I don't know any other methods to visualize 3d vector field. If you know any, e-mail me and I shall add it to MathGL. @c ------------------------------------------------------------------ -@node Hints, , More samples, Examples +@node Hints, FAQ, Vector field samples, Examples @section Hints In this section I have included some small hints and advices for the improving of the quality of plots and for the demonstration of some non-trivial features of MathGL library. In contrast to previous examples I showed mostly the idea but not the whole drawing function. @@ -1377,7 +2830,7 @@ It is an interesting result, is not it? @node Vector field visualization, Several light sources, Management of a point cutting, Hints @subsection Vector field visualization -Vector field visualization (especially in 3d case @code{Vect3} or @code{VectC}) may look tangly -- there are too many overlapping lines. I may suggest 2 ways to solve this problem. The first one is to change @code{MeshNum} for decreasing the number of hachures. The second way is to use the flow thread chart @code{Flow}. Unfortunately, I don't know any other methods to visualize 3d vector field. If you know any, e-mail me and I shall add it to MatGL. +Vector field visualization (especially in 3d case @code{Vect3} or @code{VectC}) may look tangly -- there are too many overlapping lines. I may suggest 2 ways to solve this problem. The first one is to change @code{MeshNum} for decreasing the number of hachures. The second way is to use the flow thread chart @code{Flow}. Unfortunately, I don't know any other methods to visualize 3d vector field. If you know any, e-mail me and I shall add it to MathGL. @c ------------------------------------------------------------------ @node Several light sources, CutMin and CutMax features, Vector field visualization, Hints @@ -1625,7 +3078,7 @@ The standard way is to use Unicode encoding for the text output. But the MathGL There are 3 general ways. First, the point with @code{NAN} value as one of the coordinates will never be plotted. Second, special variables @var{CutMin}, @var{CutMax} or function @code{CutOff}() define the condition when the points should be omitted (@pxref{Cutting}). Last, you may change the transparency of a part of the plot by the help of functions @code{SurfA()}, @code{Surf3A()} (@pxref{Dual plotting}). In this last case the transparency is switched on smoothly. @item I use VisualStudio, CBuilder or some other compiler (not MinGW/gcc). How can I link the MathGL library? -In version 2.0, the recomended class @code{mglGraph} (header file @code{#include }) contains only @code{inline} functions and is acceptable for any compiler with the same binary files. However, if you plan to access low-level features (i.e. classes mglBase, mglCanvas and so on) then you have to recompile MathGL by yours compiler. +In version 2.0, the recommended class @code{mglGraph} (header file @code{#include }) contains only @code{inline} functions and is acceptable for any compiler with the same binary files. However, if you plan to access low-level features (i.e. classes mglBase, mglCanvas and so on) then you have to recompile MathGL by yours compiler. @c @strong{Finally!} Please @emph{do not} ask me Windows-specific questions. I do not use Windows. I know nothing about Visual Basic, Visual C++, CBuiled or .NET. Please find the appropriate Usenet discussion group and ask your question there. @@ -1711,3 +3164,34 @@ First, you should download new font files from @uref{http://mathgl.sourceforge.n Just set a negative value in @var{SetTickLen}. For example, use @code{gr->SetTickLen(-0.1);}. @end table + + + +@c ------------------------------------------------------------------ +@node Surface transparency, , Plots for 3D data, Data plotting +@subsection Surface transparency + +MathGL library has advanced features for setting and handling the surface transparency. The simplest way to add transparency is the using of function @code{Alpha()}. As a result, all further surfaces (and isosurfaces, density plots and so on) become transparent. However, their look can be additionally improved. + +First, the selected surface will be non-transparent if one sets the flag @code{Transparent} before the surface drawing and sets it off after the drawing. + +Second, the value of transparency can be different from surface to surface. To do it just change the value of @code{AlphaDef} before the drawing of the selected surface. If its value is close to 0 then the surface becomes more and more transparent. Contrary, if its value is close to 1 then the surface becomes practically non-transparent. This is some analogue of @code{Transparent=true}. + +Third feature is the changing of the way how the light goes through overlapped surfaces. The variable @code{TranspType} defines it. By default the usual transparency is used (@code{TranspType=0}) -- surfaces below is less visible than the upper ones. A ``glass-like'' transparency (@code{TranspType=1}) has a different look when the surface just decreases the background light (the surfaces are commutable in this case). + +A ``neon-like'' transparency (@code{TranspType=2}) has more interesting look. In this case a surface is the light source (like a lamp on the dark background) and just adds some intensity to the color. At this, the library sets automatically the black color for the background and changes the default line color to white. + +As example I shall show the variant of plot from @ref{Plots for 2D data} (grid drawing is disabled) for different types of transparency. +@float +@image{../png/type0, 7cm} +@caption{Example of @code{TranspType=0}.} +@end float +@float +@image{../png/type1, 7cm} +@caption{Example of @code{TranspType=1}.} +@end float +@float +@image{../png/type2, 7cm} +@caption{Example of @code{TranspType=2}.} +@end float + diff --git a/todo.txt b/todo.txt index 7c51cc4..b179082 100644 --- a/todo.txt +++ b/todo.txt @@ -1,11 +1,12 @@ ============= TEST ============= -1. MGL testing system +1. MGL testing system ??? 2. test pthread for windows -3. Check export to MGLD/TeX/OBJ/XGL/X3D/STL. +3. Check export to MGLD/X3D. 4. add XInitThreads() from #include into all GUI 5. Check MGLD in mglview 6. check Hankel() +7. check Chart() -- '#' style + missing face!!! ============= NEW ============= @@ -14,7 +15,7 @@ ============= FOR V.2.1 ======== 1. MPI_Send(), MPI_Recv() -2. Use Hershey as built-in font ??? +2. Use Hershey as built-in font ?!! 3. Import/Export via GIF (as 3d data) ??? 4. Read DICOM files. 5. Export to JavaScript (WebGL) @@ -37,6 +38,7 @@ 20. ReadHDF5 -- add string argument for handling lowest dimension (like complex numbers): "sum" - sum, "arg" - arg, "0...9" read slice 0...9, "abs" - sqrt(sum []^2) 21. Change if possible long to size_t (be very accurate!!!) +22. Add mglDataC for complex data -- main diff is reading/saving data ============= UDAV ============= @@ -126,16 +128,17 @@ Remove other setting if data name is changed. + 2. Examples + 2.1 Basic usage (window; file; memory; QMathGL; Fl_MathGL; PyQt) +----add sample for window in python/octave (like pthread) + 2.2 Advanced usage (subplots; axis; curv.coor; text) - 2.3 Data handling - 2.4 1D data plotting - 2.5 2D data plotting - 2.6 3D data plotting - 2.7 Dual data plotting - 2.8 More samples - 2.9 Multi-threading ++ 2.3 Data handling ++ 2.4 Data plotting ++ 2.5 1D data plotting ++ 2.6 2D data plotting ++ 2.7 3D data plotting + 2.8 Dual data plotting + 2.9 More samples 2.10 Hints - 2.11 FAQ + 2.12 FAQ + 3. General concepts (class-diagram) + 3.1 Coordinate axes diff --git a/udav/CMakeLists.txt b/udav/CMakeLists.txt index 43912ff..1f74afd 100644 --- a/udav/CMakeLists.txt +++ b/udav/CMakeLists.txt @@ -1,5 +1,4 @@ -if(use_qt) - +if(MGL_HAVE_QT) #set(mgl_wnd_src window.cpp) set(udav_src anim_dlg.cpp find_dlg.cpp mem_pnl.cpp prop_dlg.cpp textedit.cpp args_dlg.cpp @@ -13,31 +12,25 @@ set(udav_moc_hdr anim_dlg.h files_dlg.h info_dlg.h opt_dlg.h qmglsyntax.h text_p set(udav_rc udav.qrc) -if(use_gsl) +if(MGL_HAVE_GSL) # target_link_libraries(mgl ${GSL_LIB} ${GSL_CBLAS_LIB} ) - add_definitions(-DHAVE_GSL) include_directories(${GSL_INCLUDE_DIR}) -else(use_gsl) - add_definitions(-DNO_GSL) -endif(use_gsl) - +endif(MGL_HAVE_GSL) include(${QT_USE_FILE}) -add_definitions(-DHAVE_QT) qt4_add_resources(udav_rc_src ${udav_rc} ) #qt_wrap_cpp(udav udav_moc_src ${udav_moc_hdr} ) qt4_wrap_cpp(udav_moc_src ${udav_moc_hdr} ) add_executable(udav ${udav_src} ${udav_moc_src} ${udav_rc_src}) target_link_libraries(udav mgl-wnd ${QT_LIBRARIES}) -if(use_pthread) +if(MGL_HAVE_PTHREAD) target_link_libraries(udav ${CMAKE_THREAD_LIBS_INIT}) - add_definitions(-DHAVE_PTHREAD) -endif(use_pthread) +endif(MGL_HAVE_PTHREAD) install( TARGETS udav RUNTIME DESTINATION bin ) -endif(use_qt) +endif(MGL_HAVE_QT) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 0267d60..3256cdb 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,27 +1,21 @@ -if(use_gsl) +if(MGL_HAVE_GSL) # target_link_libraries(mgl ${GSL_LIB} ${GSL_CBLAS_LIB} ) - add_definitions(-DHAVE_GSL) include_directories(${GSL_INCLUDE_DIR}) -else(use_gsl) - add_definitions(-DNO_GSL) -endif(use_gsl) +endif(MGL_HAVE_GSL) -if(use_fltk) - add_definitions(-DHAVE_FLTK) +if(MGL_HAVE_FLTK) include_directories(${FLTK_INCLUDE_DIR}) set(mgl_wnd_src ${mgl_wnd_src} fltk.cpp) -endif(use_fltk) -if(use_wx) +endif(MGL_HAVE_FLTK) +if(MGL_HAVE_WX) include(${wxWidgets_USE_FILE}) - add_definitions(-DHAVE_WX) set(mgl_wnd_src ${mgl_wnd_src} wx.cpp) -endif(use_wx) -if(use_qt) +endif(MGL_HAVE_WX) +if(MGL_HAVE_QT) include(${QT_USE_FILE}) - add_definitions(-DHAVE_QT) qt_wrap_cpp(mgl-qt MGL_MOC_FILES ../include/mgl/mgl_qt.h) set(mgl_wnd_src ${mgl_wnd_src} qt.cpp ${MGL_MOC_FILES}) -endif(use_qt) +endif(MGL_HAVE_QT) @@ -32,12 +26,11 @@ install( RUNTIME DESTINATION bin ) -if(use_fltk OR use_qt) +if(MGL_HAVE_FLTK OR MGL_HAVE_QT) add_executable(mglview mglview.cpp) target_link_libraries(mglview mgl-wnd) install( TARGETS mglview RUNTIME DESTINATION bin ) -endif(use_fltk OR use_qt) - +endif(MGL_HAVE_FLTK OR MGL_HAVE_QT) diff --git a/widgets/CMakeLists.txt b/widgets/CMakeLists.txt index 27c1677..78cb132 100644 --- a/widgets/CMakeLists.txt +++ b/widgets/CMakeLists.txt @@ -2,23 +2,18 @@ set(mgl_wnd_hdr ../include/mgl/window.h) set(mgl_wnd_src window.cpp) #set(mgl_wnd_src ) -if(use_gsl) +if(MGL_HAVE_GSL) # target_link_libraries(mgl ${GSL_LIB} ${GSL_CBLAS_LIB} ) - add_definitions(-DHAVE_GSL) include_directories(${GSL_INCLUDE_DIR}) -else(use_gsl) - add_definitions(-DNO_GSL) -endif(use_gsl) +endif(MGL_HAVE_GSL) -if(use_fltk) - add_definitions(-DHAVE_FLTK) +if(MGL_HAVE_FLTK) include_directories(${FLTK_INCLUDE_DIR}) set(mgl_wnd_src ${mgl_wnd_src} fltk.cpp) set(mgl_wnd_hdr ${mgl_wnd_hdr} ../include/mgl/fltk.h) -endif(use_fltk) +endif(MGL_HAVE_FLTK) -if(use_glut) - add_definitions(-DHAVE_GLUT) +if(MGL_HAVE_GLUT) include_directories(${GLUT_INCLUDE_DIR}) set(mgl_glut_src glut.cpp window.cpp) set(mgl_glut_hdr ../include/mgl/glut.h ../include/mgl/window.h) @@ -32,10 +27,9 @@ if(use_glut) target_link_libraries(mgl-glut mgl) target_link_libraries(mgl-glut ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES}) - if(use_pthread) + if(MGL_HAVE_PTHREAD) target_link_libraries(mgl-glut ${CMAKE_THREAD_LIBS_INIT}) - add_definitions(-DHAVE_PTHREAD) - endif(use_pthread) + endif(MGL_HAVE_PTHREAD) install( TARGETS mgl-glut mgl-glut-static @@ -43,23 +37,21 @@ if(use_glut) ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) -endif(use_glut) +endif(MGL_HAVE_GLUT) -if(use_wx) +if(MGL_HAVE_WX) include(${wxWidgets_USE_FILE}) - add_definitions(-DHAVE_WX) set(mgl_wnd_src ${mgl_wnd_src} wx.cpp) set(mgl_wnd_hdr ${mgl_wnd_hdr} ../include/mgl/fltk.h) -endif(use_wx) +endif(MGL_HAVE_WX) -if(use_qt) +if(MGL_HAVE_QT) include(${QT_USE_FILE}) - add_definitions(-DHAVE_QT) # qt_wrap_cpp(mgl-wnd MGL_MOC_FILES ../include/mgl/qt.h) qt4_wrap_cpp(MGL_MOC_FILES ../include/mgl/qt.h) set(mgl_wnd_src ${mgl_wnd_src} qt.cpp ${MGL_MOC_FILES}) set(mgl_wnd_hdr ${mgl_wnd_hdr} ../include/mgl/qt.h) -endif(use_qt) +endif(MGL_HAVE_QT) add_library(mgl-wnd SHARED ${mgl_wnd_src} ${mgl_wnd_hdr}) add_library(mgl-wnd-static STATIC ${mgl_wnd_src} ${mgl_wnd_hdr}) @@ -70,22 +62,21 @@ set_target_properties(mgl-wnd PROPERTIES SOVERSION 6.0.0) target_link_libraries(mgl-wnd mgl) -if(use_pthread) +if(MGL_HAVE_PTHREAD) target_link_libraries(mgl-wnd ${CMAKE_THREAD_LIBS_INIT}) - add_definitions(-DHAVE_PTHREAD) -endif(use_pthread) +endif(MGL_HAVE_PTHREAD) -if(use_fltk) +if(MGL_HAVE_FLTK) target_link_libraries(mgl-wnd ${FLTK_LIBRARIES}) -endif(use_fltk) +endif(MGL_HAVE_FLTK) -if(use_wx) +if(MGL_HAVE_WX) target_link_libraries(mgl-wnd ${wxWidgets_LIBRARIES}) -endif(use_wx) +endif(MGL_HAVE_WX) -if(use_qt) +if(MGL_HAVE_QT) target_link_libraries(mgl-wnd ${QT_LIBRARIES}) -endif(use_qt) +endif(MGL_HAVE_QT) install( TARGETS mgl-wnd mgl-wnd-static -- 2.30.2