From: Dimitrios Eftaxiopoulos Date: Sun, 25 Mar 2018 23:51:14 +0000 (+0300) Subject: New upstream version 2.4.2 X-Git-Tag: archive/raspbian/2.5-2+rpi1^2~26^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=68d98591b9c873ad5b8a62e33de4ea7f6613c572;p=mathgl.git New upstream version 2.4.2 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index df67e61..a2a3ab3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,16 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.1.0) if(POLICY CMP0043) cmake_policy(SET CMP0043 OLD) endif() -project( MathGL ) +project( MathGL2 ) +set(mgl_clean_files ) set(MGL_DEP_LIBS) +add_definitions(-DMGL_SRC) + +#add_definitions(-DZLIB_WINAPI) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${MathGL2_SOURCE_DIR}/scripts) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: @@ -14,8 +19,49 @@ endif(NOT CMAKE_BUILD_TYPE) set(CMAKE_VERBOSE_MAKEFILE ON) set(MathGL_VERSION_MAJOR 2) -set(MathGL_VERSION_MINOR 3.5) -set(MathGL_SOVERSION 7.4.3) +set(MathGL_VERSION_MINOR 4) +set(MathGL_PATCH_VERSION 2) +set(MathGL_VERSION ${MathGL_VERSION_MAJOR}.${MathGL_VERSION_MINOR}.${MathGL_PATCH_VERSION}) +set(MathGL_SOVERSION 7.5.0) +string(TIMESTAMP MathGL_DATE UTC) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + option(enable-lcov "Enable coverage." OFF) + if(enable-lcov) + include(CodeCoverage) + APPEND_COVERAGE_COMPILER_FLAGS() + endif(enable-lcov) +else(CMAKE_BUILD_TYPE STREQUAL "Debug") + unset(enable-lcov CACHE) +endif(CMAKE_BUILD_TYPE STREQUAL "Debug") + +#set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) +set(MathGL_INSTALL_LIB_DIR "lib" CACHE PATH "Installation directory for libraries") +set(MathGL_INSTALL_BIN_DIR "bin" CACHE PATH "Installation directory for executables") +set(MathGL_INSTALL_INCLUDE_DIR "include" CACHE PATH "Installation directory for headers") +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKE_DIR cmake) +else() + set(DEF_INSTALL_CMAKE_DIR lib/cmake/mathgl) +endif() +set(MathGL_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") +# Make relative paths absolute (needed later on) +foreach(p LIB BIN INCLUDE CMAKE) + set(var MathGL_INSTALL_${p}_DIR) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() +endforeach() + +macro(mgl_po_src) + set(l_files ) + foreach(src_file ${ARGN}) + get_filename_component(fp ${src_file} ABSOLUTE) + file(RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${fp}) + list(APPEND l_files "${rel}") + endforeach(src_file ${ARGN}) + set(po_files ${po_files} ${l_files} PARENT_SCOPE) +endmacro(mgl_po_src) function(mgl_add_lib mgl_tmp_lib) if(${mgl_tmp_lib} MATCHES mgl) @@ -57,9 +103,10 @@ function(mgl_add_lib mgl_tmp_lib) install( TARGETS ${mgllib} ${mgllib}-static - RUNTIME DESTINATION bin - ARCHIVE DESTINATION ${MGL_LIB_INSTALL_DIR} - LIBRARY DESTINATION ${MGL_LIB_INSTALL_DIR} + EXPORT MathGLTargets + RUNTIME DESTINATION ${MathGL_INSTALL_BIN_DIR} + ARCHIVE DESTINATION ${MathGL_INSTALL_LIB_DIR} + LIBRARY DESTINATION ${MathGL_INSTALL_LIB_DIR} ) endfunction(mgl_add_lib mgl_tmp_lib) @@ -106,9 +153,12 @@ MACRO(MGL_DEPENDENT_OPTION option doc default depends1 force1 depends2 force2) ENDMACRO(MGL_DEPENDENT_OPTION) include(CMakeDependentOption) -set(MGL_LIB_INSTALL_DIR "lib" CACHE STRING "Set library install directory") string(TIMESTAMP MGL_NIGHT "%d.%m.%y") +if(WIN32) + option(enable-dep-dll "Enable copying off all dependent dll libraries to the install directory" OFF) +endif(WIN32) + option(enable-double "Enable double precision in MathGL library" ON) option(enable-mpi "Enable mpi") option(enable-opengl "Enable OpenGL support" ON) @@ -119,7 +169,11 @@ option(enable-all-widgets "Enable all Widgets") option(enable-all-swig "Enable all SWIG based interfaces") option(enable-rvalue "Enable move constructor support (need C++11)" OFF) option(enable-pthread "Enable POSIX threads support" OFF) -option(enable-pthr-widget "Enable POSIX threads for widgets" ON) +if(MSVC) + option(enable-pthr-widget "Enable POSIX threads for widgets" OFF) +else(MSVC) + option(enable-pthr-widget "Enable POSIX threads for widgets" ON) +endif(MSVC) option(enable-openmp "Enable OpenMP support" ON) if(enable-pthread AND enable-openmp) @@ -129,13 +183,14 @@ endif(enable-pthread AND enable-openmp) option(enable-lgpl "Enable only LGPL part of MathGL") option(enable-mgl2 "Use names 'libmgl2-*' instead of 'libmgl-*'") option(enable-ltdl "Enable loading modules support") -CMAKE_DEPENDENT_OPTION(enable-doc-site "Enable HTML documentation for website" OFF "NOT enable-all-docs" ON) +option(enable-doc-site "Enable HTML documentation for website") +#CMAKE_DEPENDENT_OPTION(enable-doc-site "Enable HTML documentation for website" OFF "NOT enable-all-docs" ON) CMAKE_DEPENDENT_OPTION(enable-doc-html "Enable HTML documentation" OFF "NOT enable-all-docs" ON) CMAKE_DEPENDENT_OPTION(enable-doc-info "Enable INFO documentation" OFF "NOT enable-all-docs" ON) CMAKE_DEPENDENT_OPTION(enable-doc-pdf-ru "Enable Russian PDF documentation" OFF "NOT enable-all-docs" ON) CMAKE_DEPENDENT_OPTION(enable-doc-pdf-en "Enable English PDF documentation" OFF "NOT enable-all-docs" ON) -CMAKE_DEPENDENT_OPTION(enable-doc-prc "Enable PDF samples for HTML docs" OFF "NOT enable-all-docs" ON) -CMAKE_DEPENDENT_OPTION(enable-doc-json "Enable JSON samples for HTML docs" OFF "NOT enable-all-docs" ON) +#CMAKE_DEPENDENT_OPTION(enable-doc-prc "Enable PDF samples for HTML docs" OFF "NOT enable-all-docs" ON) +#CMAKE_DEPENDENT_OPTION(enable-doc-json "Enable JSON samples for HTML docs" OFF "NOT enable-all-docs" ON) option(enable-texi2html "Use texi2html (obsolete package) instead of texi2any" OFF) CMAKE_DEPENDENT_OPTION(enable-mgltex "Enable installation of mgltex package (MGL scripts in LATEX document)" OFF "NOT enable-lgpl" OFF) @@ -161,6 +216,19 @@ if(MSVC AND MSVC_VERSION GREATER 1899) SET(CMAKE_C_FLAGS "-D_CRT_STDIO_ISO_WIDE_SPECIFIERS ${CMAKE_C_FLAGS}") endif(MSVC AND MSVC_VERSION GREATER 1899) +include(CheckCXXSourceCompiles) + +if(${CMAKE_SIZEOF_VOID_P} EQUAL 4) + set(CMAKE_REQUIRED_FLAGS -msse2 -mfpmath=sse) + CHECK_CXX_SOURCE_COMPILES(" + int main(void){}" mgl_sse) + if(mgl_sse) + SET(CMAKE_CXX_FLAGS "-msse2 -mfpmath=sse ${CMAKE_CXX_FLAGS}") + SET(CMAKE_C_FLAGS "-msse2 -mfpmath=sse ${CMAKE_C_FLAGS}") + endif(mgl_sse) + unset(CMAKE_REQUIRED_FLAGS) +endif(${CMAKE_SIZEOF_VOID_P} EQUAL 4) + if(enable-qt4 OR enable-qt5) set(QT_ENABLED ON) if(enable-qt4asqt AND enable-qt5asqt) @@ -177,15 +245,17 @@ if(enable-qt4 OR enable-qt5) # endif(NOT enable-opengl) endif(enable-qt4 OR enable-qt5) -CMAKE_DEPENDENT_OPTION(enable-json-sample "Enable JSON sample" ON "QT_ENABLED" OFF) +CMAKE_DEPENDENT_OPTION(enable-json-sample "Enable JSON sample (WebKit variant is the default)." ON "QT_ENABLED" OFF) +CMAKE_DEPENDENT_OPTION(enable-json-sample-we "Enable JSON sample (WebEngine variant)." OFF "enable-json-sample" OFF) MGL_DEPENDENT_OPTION(enable-python "Enable python interface" OFF "NOT enable-lgpl" ON "NOT enable-all-swig" ON) MGL_DEPENDENT_OPTION(enable-lua "Enable Lua (v.5.1) interface" OFF "NOT enable-lgpl" ON "NOT enable-all-swig" ON) MGL_DEPENDENT_OPTION(enable-octave "Enable octave interface" OFF "NOT enable-lgpl" ON "NOT enable-all-swig" ON) MGL_DEPENDENT_OPTION(enable-octave-install "Octave interface will install for all users" ON "NOT enable-lgpl" ON "NOT enable-all-swig" ON) -include_directories( ${MathGL_SOURCE_DIR}/include ${MathGL_BINARY_DIR}/include) +include_directories( ${MathGL2_SOURCE_DIR}/include ${MathGL2_BINARY_DIR}/include) set(MGL_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/include/mgl2") -set(MGL_CGI_PATH "${CMAKE_INSTALL_PREFIX}/share/mathgl" CACHE STRING "Set CGI install directory") +set(MGL_CGI_PATH_INSTALL "share/mathgl" CACHE STRING "Set CGI install directory") +set(MGL_CGI_PATH "${CMAKE_INSTALL_PREFIX}/${MGL_CGI_PATH_INSTALL}") set(MGL_DEF_FONT "STIX" CACHE STRING "Set default font name") if(NOT WIN32) @@ -230,7 +300,6 @@ endif(HAVE_MEMRCHR) include(CheckTypeSize) check_type_size("long" SIZEOF_LONG) -include(CheckCXXSourceCompiles) #unset(MGL_HAVE_C99_COMPLEX) CHECK_CXX_SOURCE_COMPILES( "#include @@ -261,14 +330,6 @@ if(NOT MGL_HAVE_ATTRIBUTE) set(MGL_HAVE_ATTRIBUTE 0) endif(NOT MGL_HAVE_ATTRIBUTE) -unset(MGL_HAVE_TYPEOF CACHE) -CHECK_CXX_SOURCE_COMPILES( -"#define mgl_isnum(a) ({typeof (a) _a = (a); _a==_a;}) -int main(){bool a=mgl_isnum(1);return 0;}" MGL_HAVE_TYPEOF) -if(NOT MGL_HAVE_TYPEOF) - set(MGL_HAVE_TYPEOF 0) -endif(NOT MGL_HAVE_TYPEOF) - if(NOT MSVC AND enable-rvalue) SET(CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") unset(MGL_HAVE_RVAL CACHE) @@ -290,7 +351,7 @@ CHECK_CXX_SOURCE_COMPILES( int main(int argc, char *args[]) { int ch = getopt(argc, args, \"1:2:3:4:5:6:7:8:9:hno:L:C:A:s:S:q:\"); return 0; }" MGL_HAVE_GETOPT) if(NOT MGL_HAVE_GETOPT) - include_directories(${MathGL_SOURCE_DIR}/addons/getopt) + include_directories(${MathGL2_SOURCE_DIR}/addons/getopt) set(getopt_lib-static getopt-static) endif(NOT MGL_HAVE_GETOPT) @@ -304,20 +365,6 @@ if(enable-qt4 OR enable-qt5) set(MGL_HAVE_QT 1) endif(enable-qt4 OR enable-qt5) -if(enable-openmp) - find_package(OpenMP) - if(OPENMP_FOUND) - set(MGL_HAVE_OMP 1) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - else(OPENMP_FOUND) - message(SEND_ERROR "Couldn't find OpenMP. You can enable POSIX threads instead.") - set(MGL_HAVE_OMP 0) - endif(OPENMP_FOUND) -else(enable-openmp) - set(MGL_HAVE_OMP 0) -endif(enable-openmp) - if(enable-mpi) set(MGL_HAVE_MPI 1) find_package(MPI REQUIRED) @@ -328,7 +375,6 @@ else(enable-mpi) set(MGL_HAVE_MPI 0) endif(enable-mpi) - if(enable-pthr-widget OR enable-pthread) if(enable-pthread) set(MGL_HAVE_PTHREAD 1) @@ -336,16 +382,32 @@ if(enable-pthr-widget OR enable-pthread) set(MGL_HAVE_PTHREAD 0) endif(enable-pthread) set(MGL_HAVE_PTHR_WIDGET 1) - include(FindThreads) + set(CMAKE_THREAD_PREFER_PTHREAD ON) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) if(NOT CMAKE_USE_PTHREADS_INIT) message(SEND_ERROR "Couldn't find POSIX threads library.") endif(NOT CMAKE_USE_PTHREADS_INIT) - set(MGL_DEP_LIBS ${CMAKE_THREAD_LIBS_INIT} ${MGL_DEP_LIBS}) + set(MGL_DEP_LIBS Threads::Threads ${MGL_DEP_LIBS}) else(enable-pthr-widget OR enable-pthread) set(MGL_HAVE_PTHR_WIDGET 0) set(MGL_HAVE_PTHREAD 0) endif(enable-pthr-widget OR enable-pthread) +if(enable-openmp) + find_package(OpenMP) + if(OPENMP_FOUND) + set(MGL_HAVE_OMP 1) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + else(OPENMP_FOUND) + message(SEND_ERROR "Couldn't find OpenMP. You can enable POSIX threads instead.") + set(MGL_HAVE_OMP 0) + endif(OPENMP_FOUND) +else(enable-openmp) + set(MGL_HAVE_OMP 0) +endif(enable-openmp) + if(enable-gsl) set(MGL_HAVE_GSL 1) find_library(GSL_LIB gsl) @@ -362,6 +424,8 @@ if(enable-gsl) CHECK_CXX_SOURCE_COMPILES("#include int main(){gsl_multifit_fdfsolver *s=0;gsl_matrix *J = 0; gsl_multifit_fdfsolver_jac(s, J);}" MGL_HAVE_GSL2) + unset(CMAKE_REQUIRED_INCLUDES) + unset(CMAKE_REQUIRED_LIBRARIES) endif(NOT GSL_LIB OR NOT GSL_CBLAS_LIB OR NOT GSL_INCLUDE_DIR) set(MGL_DEP_LIBS ${GSL_LIB} ${GSL_CBLAS_LIB} ${MGL_DEP_LIBS}) include_directories(${GSL_INCLUDE_DIR}) @@ -386,9 +450,9 @@ endif(enable-all OR enable-ltdl) if(enable-hdf4) set(MGL_HAVE_HDF4 1) - find_library(HDF4_LIB df) + find_library(HDF4_LIB NAMES df hdf) find_library(HDF4MF_LIB mfhdf) - find_path(HDF4_INCLUDE_DIR hdf/mfhdf.h) + find_path(HDF4_INCLUDE_DIR mfhdf.h PATH_SUFFIXES hdf) if(NOT HDF4_LIB OR NOT HDF4MF_LIB OR NOT HDF4_INCLUDE_DIR) message(SEND_ERROR "${HDF4_LIB}") message(SEND_ERROR "${HDF4MF_LIB}") @@ -411,7 +475,7 @@ if(enable-hdf5) endif(NOT HDF5_FOUND) endif(NOT HDF5_FOUND) set(MGL_DEP_LIBS ${HDF5_LIBRARIES} ${HDF5_C_SHARED_LIBRARY} ${MGL_DEP_LIBS}) - include_directories(${HDF5_INCLUDE_DIR}) + include_directories(${HDF5_INCLUDE_DIRS}) else(enable-hdf5) set(MGL_HAVE_HDF5 0) endif(enable-hdf5) @@ -515,10 +579,18 @@ endif(enable-glut) if(enable-fltk) set(MGL_HAVE_FLTK 1) - include(FindFLTK) + FIND_PACKAGE(FLTK) if(NOT FLTK_FOUND) message(SEND_ERROR "Couldn't find FLTK library.") + else(NOT FLTK_FOUND) + include_directories(${FLTK_INCLUDE_DIR}) + CHECK_CXX_SOURCE_COMPILES( + "#include + int main(){return 0;}" MGL_HAVE_FL_COPY) endif(NOT FLTK_FOUND) + if(NOT MGL_HAVE_FL_COPY) + set(MGL_HAVE_FL_COPY 0) + endif(NOT MGL_HAVE_FL_COPY) else(enable-fltk) set(MGL_HAVE_FLTK 0) endif(enable-fltk) @@ -533,6 +605,32 @@ else(enable-wx) set(MGL_HAVE_WX 0) endif(enable-wx) + +find_program(findxgettext xgettext) +find_program(findmsgmerge msgmerge) +find_program(findmsgfmt msgfmt) +find_program(findmsgcat msgcat) +if(NOT findmsgfmt OR NOT findxgettext OR NOT findmsgmerge OR NOT findmsgcat ) + message("Building of translation files was disabled, because xgettext, msgmerge, msgcat or msgfmt was not found. Current translations will be just coped.") + set(USE_GETTEXT 0) +else(NOT findmsgfmt OR NOT findxgettext OR NOT findmsgmerge OR NOT findmsgcat ) + set(USE_GETTEXT 1) +endif(NOT findmsgfmt OR NOT findxgettext OR NOT findmsgmerge OR NOT findmsgcat ) +find_package(Intl) +if(NOT Intl_FOUND) + set(MGL_USE_LIBINTL 0) + message("Gettext and translations was fully disabled, because libintl was not found.") +else(NOT Intl_FOUND) + set(MGL_USE_LIBINTL 1) + set(MGL_DEP_LIBS ${Intl_LIBRARIES} ${MGL_DEP_LIBS}) + include_directories(${Intl_INCLUDE_DIRS}) +endif(NOT Intl_FOUND) +set(po_files ) +if(WIN32) + set(USE_GETTEXT 0) + set(MGL_USE_LIBINTL 0) +endif(WIN32) + if(enable-doc-info) set(MGL_HAVE_DOC_INFO 1) find_program(findmi makeinfo) @@ -599,20 +697,20 @@ else(enable-doc-pdf-en) set(MGL_HAVE_DOC_PDF_EN 0) endif(enable-doc-pdf-en) -if(enable-doc-json) +if(enable-doc-site) set(MGL_HAVE_DOC_JSON 1) -else(enable-doc-json) +else(enable-doc-site) set(MGL_HAVE_DOC_JSON 0) -endif(enable-doc-json) +endif(enable-doc-site) -if(enable-doc-prc) +if(enable-doc-site) set(MGL_HAVE_DOC_PRC 1) if(NOT enable-pdf) message(SEND_ERROR "You need to enable pdf support for MathGL.") endif(NOT enable-pdf) -else(enable-doc-prc) +else(enable-doc-site) set(MGL_HAVE_DOC_PRC 0) -endif(enable-doc-prc) +endif(enable-doc-site) if(UNIX) add_definitions(-DNO_COLOR_ARRAY) @@ -630,17 +728,21 @@ add_subdirectory( src ) add_subdirectory( widgets ) add_subdirectory( include ) if(NOT enable-lgpl) - add_subdirectory( udav ) - add_subdirectory( json ) + if(MGL_HAVE_QT) + add_subdirectory( udav ) + if(enable-json-sample) + add_subdirectory( json ) + endif(enable-json-sample) + endif(MGL_HAVE_QT) if(enable-python OR enable-lua OR enable-octave) add_subdirectory( lang ) endif(enable-python OR enable-lua OR enable-octave) add_subdirectory( utils ) add_subdirectory( examples ) - if(NOT WIN32) - add_subdirectory( fonts ) - endif(NOT WIN32) -# add_subdirectory( mgllab ) +if(NOT WIN32) + add_subdirectory( fonts ) +endif(NOT WIN32) +add_subdirectory( mgllab ) endif(NOT enable-lgpl) if(NOT MSVC AND NOT BORLAND) @@ -655,8 +757,36 @@ if(enable-mgltex) add_subdirectory( mgltex ) endif(enable-mgltex) -if(WIN32) - install(FILES ${CMAKE_SOURCE_DIR}/FindMathGL2.cmake DESTINATION ${CMAKE_INSTALL_PREFIX} RENAME mathgl2-config.cmake) -else(WIN32) - install(FILES ${CMAKE_SOURCE_DIR}/FindMathGL2.cmake DESTINATION ${MGL_LIB_INSTALL_DIR}/cmake/mathgl2/ RENAME mathgl2-config.cmake) -endif(WIN32) +if(MGL_USE_LIBINTL) + if(USE_GETTEXT) + set(mgl_tl_list ) + add_custom_command(OUTPUT mathgl.pot + COMMAND ${findxgettext} -s --keyword=_ -C -c --package-name=MathGL2 --package-version=${MathGL_VERSION} -o ${MathGL2_BINARY_DIR}/mathgl.pot ${po_files} + WORKING_DIRECTORY ${MathGL2_SOURCE_DIR}/ + DEPENDS ${po_files} ) + set(mgl_clean_files mathgl.pot ${mgl_clean_files}) + foreach(tl ru es) # en) + add_custom_command(OUTPUT mathgl_${tl}.po.done + COMMAND ${findmsgmerge} -U mathgl_${tl}.po ${MathGL2_BINARY_DIR}/mathgl.pot + COMMAND ${CMAKE_COMMAND} -E touch ${MathGL2_BINARY_DIR}/mathgl_${tl}.po.done + WORKING_DIRECTORY ${MathGL2_SOURCE_DIR}/ + DEPENDS mathgl.pot mathgl_${tl}.po) + add_custom_command(OUTPUT mathgl_${tl}.mo + COMMAND ${findmsgfmt} -o mathgl_${tl}.mo ${MathGL2_SOURCE_DIR}/mathgl_${tl}.po + DEPENDS mathgl_${tl}.po.done) + install( FILES ${MathGL2_BINARY_DIR}/mathgl_${tl}.mo DESTINATION "${CMAKE_INSTALL_PREFIX}/share/locale/${tl}/LC_MESSAGES/" RENAME mathgl.mo ) + set(mgl_tl_list mathgl_${tl}.mo ${mgl_tl_list}) + set(mgl_clean_files mathgl_${tl}.mo mathgl_${tl}.po.done ${mgl_clean_files}) + endforeach(tl) + add_custom_target(mgl_translations ALL DEPENDS ${mgl_tl_list}) + else(USE_GETTEXT) + foreach(tl ru es) # en) + install( FILES ${MathGL2_SOURCE_DIR}/translations/mathgl_${tl}.mo DESTINATION "${CMAKE_INSTALL_PREFIX}/share/locale/${tl}/LC_MESSAGES/" RENAME mathgl.mo ) + endforeach(tl) + endif(USE_GETTEXT) +endif(MGL_USE_LIBINTL) + +set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${mgl_clean_files}") + +# WARNING!!! DO NOT ADD ANYTHING AFTER THIS LINE! +add_subdirectory ( scripts ) diff --git a/ChangeLog.txt b/ChangeLog.txt index c47c176..99a53dd 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,91 @@ -2.3.5.1 Released 2 June 2016 + +2.4.2 Released 21 March 2018 + +* Add custom dialog for FLTK widgets. This can be constructed from C/C++ code, or from MGL script using special comments "##d##d $I kind|label|par1|par2|..." will create an entry in custom dialog for changing plot properties. Here "$I" is id ($0,$1...$9,$a,$b...$z), "label" is the label of element, "kind" is one following: + 'e' for editor or input line (parameter is initial value) , + 'v' for spinner or counter (parameters are "ini|min|max|step|big_step"), + 's' for slider (parameters are "ini|min|max|step"), + 'b' for check box (parameter is "ini"; also understand "on"=1), + 'c' for choice (parameters are possible choices). +* Add 'progress' for displaying the progress of execution (by '#' symbols in console, or by progress-bar widget). +* Add 'contp' for contour lines on parametrically specified surface. +* Add 'flow3' for flow threads of 3D vector field, which start from the plain. +* Add variant of 'flow' for drawing a flow thread, starting from specified point. +* Add 'scaletext' for disabling text size scaling in relative inplots (like columnplot, ...). +* Add 'setup' for setting all low-level flags. +* Add 'coil' for projecting periodical data. +* Add modulo operation "%" (x%y=fmod(x,y)) to the list of known operations in real-valued formulas. +* Add style '.' for 'cont' to draw contour lines from saddle points. +* Add style '.' for 'flow' to draw flow thread from saddle points. +* Add option 'value' in 'tube' for setting number of edges manually. +* Crop output of 'ode' if NAN or INFINITY value occurs. +* Remove style '~' for 'plot' and 'tens'. Now, all curves try to omit points. +* Add setup flag MGL_FULL_CURV which disable omitting points of curve. +* Shift axis labels closer to axis. +* Change size of LaTeX-like commands \sup, \sub to be the same as \overset, \underset. +* Change ticks drawing in colorbar. +* Add new section "All samples" of documentation with large set of samples for most of MathGL features. +* Samples in documentation are generated automatically now (from sample.cpp). +INCOMPATIBLE: +* Make obsolete MGL command 'setsizescl'. At this, the similar C/C++/Fortran/... functions still working. + + +2.4.1 Released 20 July 2017 + +* Add 'beltc' plot, which is 'belt' with manual coloring. +* Add style '~' for 'plot' and 'tens' to omit some points at output. +* Add style ':' for 'axis' to draw lines through point (0,0,0). +* Bugfixes + +2.4 Released 17 May 2017 + +* Add mgllab executable, which is FLTK based version of UDAV. Most things mgllab do faster. +* Add string manipulation in MGL language: + o 'str'[n] -- get string of only n-th symbol; + o 'str'+v -- add value v to the last character of the string; + o 'str',val || 'str',!val -- append numeric value to the string (as before). +* Add time value to MGL language in format: "hh-mm-ss_DD.MM.YYYY" or "hh-mm-ss" or "DD.MM.YYYY". +* Add 'iris' plot to show cross-dependencies of several data arrays. +* Add 'flame2d' to draw flame fractals. +* Add 'bbox' to set bounding box for 2D output. +* Add 'section' to get part of data between specified values. +* Add 'detect' to found curves along data maximums. +* Add 'dilate' to extend the region of 1-th value. +* Add 'erode' to narrow the region of 1-th value. +* Add 'apde' to solve PDE equation in inhomogeneous nonlinear media with spatial dispersion. +* Add 'symbol' to draw the glyphs defined by 'addsymbol'. +* Add 'addsymbol' to declare user-defined symbol (or glyph), which can be used as markers for plot (with style '&') or drawn itself by 'symbol' command. +* Add 'openhdf' to open all data arrays from HDF file. +* Extend 'crop' to cut to optimal size for FFT (i.e. to closest of 2^n*3^m*5^l). +* Add function mgl_data_max_first() and data suffixes .m[xyz][fl] to find first/last maximum along direction. +* Add function mgl_datac_diff_par() to parametric derivative of complex data. +* Add style 'F' for 'bars' and 'barh' to set fixed bar widths. +* Add style 'a' for 'plot', 'tens', 'area' and 'region' to accurate drawing of data, which partially lie out of axis range. +* Add style '#' for 'region' to draw wired plot. +* Add possibility of manual shift in 'multiplot'. +* Add parsing arguments of options for MGL commands. +* MGL command 'correl' now can perform 2d and 3d correlations. +* Option 'meshnum' now change the number of drawn markers for 'plot', 'tens', 'step, 'mark' and 'textmark'. +* Function 'step' handle data with x.nx>y.nx similarly to 'bars'. +* Extend 'tile' and 'tiles' by adding manual coloring and face orientation. +* Add variant of MGL command 'copy' to copy data with "incorrect" names. +* Improve tick labels drawing. +* Improve time-ticks (add weeks) and add subticks to its. +* Improve 'fplot' to handle several singularities. +* Add LaTeX command \dfrac{}{}. This is full-sized version of \frac{}{}. Unfortunately, there is no support of nesting (i.e. \dfrac{\dfrac{}{}}{} not working). Contrary, \frac{}{} allow nesting. +* Add mglODEc() -- ODE solver for complex variables. +* Add cmplx(a,b)=a+i*b to the list of known functions in formula parsing +* Update CMake find_package to find MathGL. +* Increase line width for wired text. +* Update documentation: add description of new commands, add hint @ref{Mixing bitmap and vector output}. +* Add translation to Russian for most of labels and messages. +* Name 'all' are reserved in MGL scripts now as synonym of -1. + +* INCOMPATIBLE: Replace libmgl-qt by libmgl-qt4 and libmgl-qt5 for resolving conflicts of simultaneously installed both Qt4 and Qt5. +* Minor bugfixes. + + +2.3.5.1 Released 20 June 2016 * INCOMPATIBLE: library libmgl-qt is removed. You need to use libmgl-qt4 or libmgl-qt5 explicitly now. * Compatibility changes for latest MS VisualStudio. diff --git a/FindMathGL2.cmake b/FindMathGL2.cmake deleted file mode 100644 index 772b505..0000000 --- a/FindMathGL2.cmake +++ /dev/null @@ -1,145 +0,0 @@ -# - FindMathGL2.cmake -# This module can be used to find MathGL v.2.* and several of its optional components. -# -# You can specify one or more component as you call this find module. -# Possible components are: FLTK, GLUT, Qt, WX. -# -# The following variables will be defined for your use: -# -# MATHGL2_FOUND = MathGL v.2 and all specified components found -# MATHGL2_INCLUDE_DIRS = The MathGL v.2 include directories -# MATHGL2_LIBRARIES = The libraries to link against to use MathGL v.2 -# and all specified components -# MATHGL2_VERSION_STRING = A human-readable version of the MathGL v.2 (e.g. 2.1) -# MATHGL2_XXX_FOUND = Component XXX found (replace XXX with uppercased -# component name -- for example, QT or FLTK) -# -# The minimum required version and needed components can be specified using -# the standard find_package()-syntax, here are some examples: -# find_package(MathGL2 REQUIRED) - v.2.* (no interfaces), required -# find_package(MathGL2 2.1 REQUIRED Qt) - v.2.1 + Qt interface, required -# find_package(MathGL2 2.1 REQUIRED) - v.2.1 (no interfaces), required -# find_package(MathGL2 2.0 COMPONENTS Qt WX) - v.2.0 + Qt and WX interfaces, optional -# find_package(MathGL2 2.1) - v.2.1 (no interfaces), optional -# -# Note, some cmake builds require to write "COMPONENTS" always, like -# find_package(MathGL2 REQUIRED COMPONENTS Qt) - v.2.* + Qt interface, required -# -# Typical usage could be something like this: -# find_package(MathGL 2.1 GLUT REQUIRED) -# include_directories(${MATHGL2_INCLUDE_DIRS}) -# add_executable(myexe main.cpp) -# target_link_libraries(myexe ${MATHGL2_LIBRARIES}) -# - -#============================================================================= -# Copyright (c) 2011 Denis Pesotsky , 2014 Alexey Balakin -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file COPYING-CMAKE-MODULES for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= - -FIND_PATH(MATHGL2_INCLUDE_DIR - NAMES mgl2/mgl.h - DOC "The MathGL2 v.2.* include directory") -FIND_LIBRARY(MATHGL2_LIBRARY - NAMES mgl - PATHS ${MATHGL2_LIBRARY_DIR} - DOC "The MathGL v.2.* include directory") - -GET_FILENAME_COMPONENT(MATHGL2_LIBRARY_DIR ${MATHGL2_LIBRARY} PATH) - -SET(MATHGL2_LIBRARIES ${MATHGL2_LIBRARY}) -SET(MATHGL2_INCLUDE_DIRS ${MATHGL2_INCLUDE_DIR}) - -IF(MATHGL2_INCLUDE_DIR) - SET(_CONFIG_FILE_PATH "${MATHGL2_INCLUDE_DIR}/mgl2/define.h") - SET(_VERSION_ERR "Cannot determine MathGL v.2.* version") - IF(EXISTS "${_CONFIG_FILE_PATH}") - FILE(STRINGS "${_CONFIG_FILE_PATH}" - MATHGL2_VERSION_STRING REGEX "^#define MGL_VER2.*$") - IF(MATHGL2_VERSION_STRING) - STRING(REGEX - REPLACE "#define MGL_VER2" "" - MATHGL2_VERSION_STRING ${MATHGL2_VERSION_STRING}) - STRING(REGEX - REPLACE "//.*" "" - MATHGL2_VERSION_STRING ${MATHGL2_VERSION_STRING}) - STRING(STRIP ${MATHGL2_VERSION_STRING} MATHGL2_VERSION_STRING) - SET(MATHGL2_VERSION_STRING 2.${MATHGL2_VERSION_STRING}) -# MESSAGE(STATUS "Find MathGL version -- ${MATHGL2_VERSION_STRING}") - ELSE() - SET(_ERR_MESSAGE "${_VERSION_ERR}: ${_CONFIG_FILE_PATH} parse error") - ENDIF() - ELSE() - SET(_ERR_MESSAGE "${_VERSION_ERR}: ${_CONFIG_FILE_PATH} not found") - ENDIF() - IF(_ERR_MESSAGE) - UNSET(_ERR_MESSAGE) - SET(_CONFIG_FILE_PATH "${MATHGL2_INCLUDE_DIR}/mgl2/config.h") - SET(_VERSION_ERR "Cannot determine MathGL v.2.* version") - IF(EXISTS "${_CONFIG_FILE_PATH}") - FILE(STRINGS "${_CONFIG_FILE_PATH}" - MATHGL2_VERSION_STRING REGEX "^#define MGL_VER2.*$") - IF(MATHGL2_VERSION_STRING) - STRING(REGEX - REPLACE "#define MGL_VER2" "" - MATHGL2_VERSION_STRING ${MATHGL2_VERSION_STRING}) - STRING(REGEX - REPLACE "//.*" "" - MATHGL2_VERSION_STRING ${MATHGL2_VERSION_STRING}) - STRING(STRIP ${MATHGL2_VERSION_STRING} MATHGL2_VERSION_STRING) - SET(MATHGL2_VERSION_STRING 2.${MATHGL2_VERSION_STRING}) - # MESSAGE(STATUS "Find MathGL version -- ${MATHGL2_VERSION_STRING}") - ELSE() - SET(_ERR_MESSAGE "${_VERSION_ERR}: ${_CONFIG_FILE_PATH} parse error") - ENDIF() - ELSE() - SET(_ERR_MESSAGE "${_VERSION_ERR}: ${_CONFIG_FILE_PATH} not found") - ENDIF() - ENDIF(_ERR_MESSAGE) - - if(_ERR_MESSAGE) - MESSAGE(FATAL_ERROR ${_ERR_MESSAGE}) - endif(_ERR_MESSAGE) -ENDIF() - -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(MathGL2 - REQUIRED_VARS MATHGL2_LIBRARY MATHGL2_INCLUDE_DIR - VERSION_VAR MATHGL2_VERSION_STRING) - -FOREACH(_Component ${MATHGL2_FIND_COMPONENTS}) - STRING(TOLOWER ${_Component} _component) - STRING(TOUPPER ${_Component} _COMPONENT) - - SET(MATHGL2_${_Component}_FIND_REQUIRED ${MATHGL2_FIND_REQUIRED}) - SET(MATHGL2_${_Component}_FIND_QUIETLY true) - # TODO find qt.h for qt4 and qt5 !!! - FIND_PATH(MATHGL2_${_COMPONENT}_INCLUDE_DIR - NAMES mgl2/${_component}.h - PATHS ${MATHGL2_INCLUDE_DIR} NO_DEFAULT_PATH) - FIND_LIBRARY(MATHGL2_${_COMPONENT}_LIBRARY - NAMES mgl-${_component} - PATHS ${MATHGL2_LIBRARY_DIR} NO_DEFAULT_PATH) - - FIND_PACKAGE_HANDLE_STANDARD_ARGS(MATHGL2_${_Component} DEFAULT_MSG - MATHGL2_${_COMPONENT}_LIBRARY - MATHGL2_${_COMPONENT}_INCLUDE_DIR) - - IF(MATHGL2_${_COMPONENT}_FOUND) - SET(MATHGL2_LIBRARIES - ${MATHGL2_LIBRARIES} ${MATHGL2_${_COMPONENT}_LIBRARY}) - SET(MATHGL2_INCLUDE_DIRS - ${MATHGL2_INCLUDE_DIRS} ${MATHGL2_${_COMPONENT}_INCLUDE_DIR}) - ENDIF() - - MARK_AS_ADVANCED(MATHGL2_${_COMPONENT}_INCLUDE_DIR - MATHGL2_${_COMPONENT}_LIBRARY) -ENDFOREACH() - -MARK_AS_ADVANCED(MATHGL2_INCLUDE_DIR MATHGL2_LIBRARY) diff --git a/addons/getopt/getopt.c b/addons/getopt/getopt.c index dd4f2c5..dd21231 100644 --- a/addons/getopt/getopt.c +++ b/addons/getopt/getopt.c @@ -55,7 +55,7 @@ enum ENUM_ORDERING { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER }; // // // Ansi structures and functions follow -// +// // static struct _getopt_data_a @@ -84,8 +84,7 @@ static void exchange_a(char **argv, struct _getopt_data_a *d) if (top - middle > middle - bottom) { int len = middle - bottom; - register int i; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; @@ -96,8 +95,7 @@ static void exchange_a(char **argv, struct _getopt_data_a *d) else { int len = top - middle; - register int i; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; @@ -515,7 +513,7 @@ int _getopt_long_only_r_a (int argc, char *const *argv, const char *options, con // // // Unicode Structures and Functions -// +// // static struct _getopt_data_w @@ -544,8 +542,7 @@ static void exchange_w(wchar_t **argv, struct _getopt_data_w *d) if (top - middle > middle - bottom) { int len = middle - bottom; - register int i; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; @@ -556,8 +553,7 @@ static void exchange_w(wchar_t **argv, struct _getopt_data_w *d) else { int len = top - middle; - register int i; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; @@ -690,7 +686,7 @@ int _getopt_internal_r_w (int argc, wchar_t *const *argv, const wchar_t *optstri if (ambig_list != NULL && !exact) { if (print_errors) - { + { struct option_list first; first.p = pfound; first.next = ambig_list; @@ -970,4 +966,4 @@ int _getopt_long_r_w (int argc, wchar_t *const *argv, const wchar_t *options, co int _getopt_long_only_r_w (int argc, wchar_t *const *argv, const wchar_t *options, const struct option_w *long_options, int *opt_index, struct _getopt_data_w *d) { return _getopt_internal_r_w (argc, argv, options, long_options, opt_index, 1, d, 0); -} \ No newline at end of file +} diff --git a/ads.txt b/ads.txt new file mode 100644 index 0000000..166586d --- /dev/null +++ b/ads.txt @@ -0,0 +1 @@ +google.com, pub-1128070552722622, DIRECT, f08c47fec0942fa0 diff --git a/cmake-qt4.txt b/cmake-qt4.txt deleted file mode 100644 index 7e661ea..0000000 --- a/cmake-qt4.txt +++ /dev/null @@ -1,20 +0,0 @@ -set(MGL_HAVE_QT4 1) -set(MGL_QT4_LIBS) -if(enable-json-sample) -set(MGL_QT4_LIBS_FIND QtCore QtGui QtNetwork QtWebKit QtOpenGL) -else(enable-json-sample) -set(MGL_QT4_LIBS_FIND QtCore QtGui QtOpenGL) -endif(enable-json-sample) - -FIND_PACKAGE(Qt4 4.8 REQUIRED ${MGL_QT4_LIBS_FIND}) - -if(NOT QT4_FOUND) - message(SEND_ERROR "Couldn't find Qt4 library.") -endif(NOT QT4_FOUND) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -foreach(mgl_qt4_lib ${MGL_QT4_LIBS_FIND}) - set(MGL_QT4_LIBS ${MGL_QT4_LIBS} Qt4::${mgl_qt4_lib}) -endforeach(mgl_qt4_lib) diff --git a/cmake-qt5.txt b/cmake-qt5.txt deleted file mode 100644 index 4b7f0b9..0000000 --- a/cmake-qt5.txt +++ /dev/null @@ -1,18 +0,0 @@ -set(MGL_HAVE_QT5 1) - -set(MGL_QT5_LIBS_FIND Core Gui Widgets PrintSupport OpenGL) - -if(enable-json-sample) - set(MGL_QT5_LIBS_FIND ${MGL_QT5_LIBS_FIND} Network WebKit WebKitWidgets) -endif(enable-json-sample) - -foreach(mgl_qt5_lib ${MGL_QT5_LIBS_FIND}) - set(MGL_QT5_LIBS ${MGL_QT5_LIBS} Qt5::${mgl_qt5_lib}) - find_package(Qt5${mgl_qt5_lib} REQUIRED) - if(NOT Qt5${mgl_qt5_lib}_FOUND) - message(SEND_ERROR "Couldn't find Qt5 ${mgl_qt5_lib} library.") - endif(NOT Qt5${mgl_qt5_lib}_FOUND) -endforeach(mgl_qt5_lib) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/emblem.mgl b/emblem.mgl index 6c330c8..a3f2473 100644 --- a/emblem.mgl +++ b/emblem.mgl @@ -1,6 +1,6 @@ setsize 1000 500 text 0.95 0.8 'MathGL' ':RiA' -4 -text 0.05 0.15 'library\n for scientific graphics' ':LiA' -2.5 +text 0.05 0.15 'library\n for scientific graphics' ':LiA' -2. #rect 0.05 0.9 2 1.5 1.34 2 'w' xtick -3:ytick -3:ztick -3 subplot 1 1 0 '^_' diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d216bef..7c25819 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,16 @@ +file(COPY ${CMAKE_SOURCE_DIR}/examples/iris.dat DESTINATION ${CMAKE_BINARY_DIR}/examples) +file(COPY ${CMAKE_SOURCE_DIR}/examples/Equirectangular-projection.jpg DESTINATION ${CMAKE_BINARY_DIR}/examples) +file(COPY ${CMAKE_SOURCE_DIR}/examples/samples.cpp DESTINATION ${CMAKE_BINARY_DIR}/examples) +file(COPY ${CMAKE_SOURCE_DIR}/examples/wnd_samples.cpp DESTINATION ${CMAKE_BINARY_DIR}/examples) add_executable(mgl_example wnd_samples.cpp full_test.cpp samples.cpp) target_link_libraries(mgl_example mgl-static ${getopt_lib-static}) +if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_COMPILER_IS_GNUCXX AND enable-lcov) + setup_target_for_coverage( + NAME mgl_coverage + EXECUTABLE $ -mgl + DEPENDENCIES mgl_example + ) +endif(CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_COMPILER_IS_GNUCXX AND enable-lcov) if(MGL_HAVE_FLTK) include_directories(${FLTK_INCLUDE_DIR}) @@ -21,10 +32,10 @@ endif(MGL_HAVE_WX) if(QT_ENABLED) add_executable(mgl_qt_example wnd_samples.cpp qt_example.cpp) if(enable-qt5) - include(../cmake-qt5.txt) + include(../scripts/qt5.cmake) target_link_libraries(mgl_qt_example mgl-qt5) else(enable-qt5) - include(../cmake-qt4.txt) + include(../scripts/qt4.cmake) target_link_libraries(mgl_qt_example mgl-qt4) endif(enable-qt5) @@ -43,3 +54,8 @@ if(MGL_HAVE_LTDL) target_link_libraries(mgl_module mgl) # for compatibility with win32 endif(MGL_HAVE_LTDL) +if(MGL_HAVE_MPI) + add_executable(mgl_mpi_example mpi_test.cpp) + target_link_libraries(mgl_mpi_example mgl-mpi mgl ${MPI_LIBRARIES}) + target_include_directories(mgl_mpi_example SYSTEM PUBLIC ${MPI_CXX_INCLUDE_PATH}) +endif(MGL_HAVE_MPI) diff --git a/examples/Equirectangular-projection.jpg b/examples/Equirectangular-projection.jpg new file mode 100644 index 0000000..bfc62ab Binary files /dev/null and b/examples/Equirectangular-projection.jpg differ diff --git a/examples/fltk_example.cpp b/examples/fltk_example.cpp index 61d39c9..9dc8db3 100644 --- a/examples/fltk_example.cpp +++ b/examples/fltk_example.cpp @@ -55,6 +55,7 @@ void *calc(void *) } int main(int argc,char **argv) { + mgl_textdomain(argv?argv[0]:NULL); static pthread_t thr; pthread_create(&thr,0,calc,0); pthread_detach(thr); @@ -65,6 +66,7 @@ int main(int argc,char **argv) mglPoint pnt; // some global variable for changeable data int main(int argc,char **argv) { + mgl_textdomain(argv?argv[0]:NULL); mglFLTK gr("test"); gr.RunThr(); // <-- need MathGL version which use pthread for(int i=0;i<10;i++) // do calculation @@ -95,7 +97,7 @@ class myDraw : public mglDraw long i; // another variable to be shown mglWnd *wnd; // external window for plotting public: - myDraw(mglWnd *w=0) : mglDraw() { wnd=w; } + myDraw(mglWnd *w=0) : mglDraw() { i=0; wnd=w; } void SetWnd(mglWnd *w) { wnd=w; } int Draw(mglGraph *gr) { @@ -119,6 +121,7 @@ public: //----------------------------------------------------------------------------- int main(int argc,char **argv) { + mgl_textdomain(argv?argv[0]:NULL,""); mglFLTK *gr; char key = 0; if(argc>1) key = argv[1][0]!='-' ? argv[1][0]:argv[1][1]; diff --git a/examples/full_test.cpp b/examples/full_test.cpp index 538dfba..714ac1b 100644 --- a/examples/full_test.cpp +++ b/examples/full_test.cpp @@ -21,11 +21,19 @@ #include #include #include +#ifdef WIN32 +#include +#include +#else +#include +#endif +#include "mgl2/base.h" #include "mgl2/mgl.h" #include "mgl2/font.h" #include "mgl2/eval.h" //----------------------------------------------------------------------------- +void smgl_fexport(mglGraph *gr); // test file export void MGL_EXPORT mgl_create_cpp_font(HMGL gr, const wchar_t *how); long MGL_EXPORT mgl_check_tex_table(); //----------------------------------------------------------------------------- @@ -34,6 +42,7 @@ struct mglSample /// Structure for list of samples const char *name; void (*func)(mglGraph*); const char *mgl; + const char *info; }; extern mglSample samp[]; extern const char *mmgl_dat_prepare; @@ -64,8 +73,9 @@ void mgls_prepare3v(mglData *ex, mglData *ey, mglData *ez); void save(mglGraph *gr,const char *name,const char *suf); void test(mglGraph *gr) { - mglData a; a.SetList(5,0.,1.,0.,1.,-1.,2.); - gr->Plot(a); +// printf("Prim=%lu, Pnt=%lu, Matrix=%lu, Color=%lu, Point=%lu, Light=%lu, ActivePos=%lu\n", +// sizeof(mglPrim), sizeof(mglPnt), sizeof(mglMatrix), sizeof(mglColor), sizeof(mglPoint), sizeof(mglLight), sizeof(mglActivePos) ); + gr->ShearPlot(3, 0, 0.2, 0.1); gr->Box("r"); return; mglParse par; par.Execute(gr,"call 'test' -1\n func 'test' 1\nline $1 0 1 1 'b'\nreturn\n"); @@ -74,6 +84,64 @@ void test(mglGraph *gr) return; } //----------------------------------------------------------------------------- +void mgl_generate_texi() +{ + FILE *fp = fopen("samples.texi","w"); + FILE *fq = fopen("samples_list.texi","w"); + fprintf(fp,"@c ------------------------------------------------------------------\n" + "@chapter All samples\n@nav{}\n\n" + "This chapter contain alphabetical list of MGL and C++ samples for most of MathGL graphics and features.\n\n@menu\n* initialization sample::\n"); + for(const mglSample *s = samp;s->name && s->name[0];s++) + fprintf(fp,"* %s sample::\n",s->name); + fprintf(fp,"@end menu\n@external{}\n"); + fprintf(fp,"@c ------------------------------------------------------------------\n" + "@node initialization sample, %s sample, , All samples\n@section Functions for initialization\n@nav{}\n", samp[0].name); + fprintf(fp,"\nThis section contain functions for input data for most of further samples.\n\n@strong{MGL code:}\n@verbatim\n%s\n@end verbatim\n", mmgl_dat_prepare); + fprintf(fp,"\n@ifclear UDAV\n@strong{C++ code:}\n@verbatim\n"); + + char buf[512], name[64]; + FILE *fs = fopen("wnd_samples.cpp","r"); + while(!feof(fs)) + { + fgets(buf,512,fs); + if(strstr(buf,"void mgls_prepare1d")) break; + } + while(!feof(fs)) + { fprintf(fp,"%s",buf); fgets(buf,512,fs); } + fprintf(fp,"\n@end verbatim\n@end ifclear\n\n@external{}\n"); + fclose(fs); + + const char *prev = "initialization"; + fs = fopen("samples.cpp","r"); + for(size_t i=0;samp[i].name && samp[i].name[0];i++) + { + fprintf(fq, "@sfig{%s, %s sample}\n", samp[i].name, samp[i].name); + if(samp[i+1].name && samp[i+1].name[0]) + fprintf(fp,"@c ------------------------------------------------------------------\n" + "@node %s sample, %s sample, %s sample, All samples\n@section Sample @samp{%s}\n@nav{}\n", + samp[i].name, samp[i+1].name, prev, samp[i].name); + else + fprintf(fp,"@c ------------------------------------------------------------------\n" + "@node %s sample, , %s sample, All samples\n@section Sample '%s'\n@nav{}\n", + samp[i].name, samp[i-1].name, samp[i].name); + prev = samp[i].name; + fprintf(fp,"\n%s\n\n@strong{MGL code:}\n@verbatim\n%s\n@end verbatim\n", samp[i].info, samp[i].mgl); + fprintf(fp,"\n@ifclear UDAV\n@strong{C++ code:}\n@verbatim\n"); + + fseek(fs,0,SEEK_SET); + snprintf(name, 64, "void smgl_%s", samp[i].name); + while(!feof(fs)) + { fgets(buf,512,fs); if(strstr(buf,name)) break; } + while(!feof(fs)) + { + fprintf(fp,"%s",buf); fgets(buf,512,fs); + if(*buf=='}') break; + } + fprintf(fp,"}\n@end verbatim\n@end ifclear\n@pfig{%s, Sample @samp{%s}}\n@external{}\n", samp[i].name, samp[i].name); + } + fclose(fs); fclose(fp); fclose(fq); +} + static struct option longopts[] = { { "big", no_argument, &big, 1 }, @@ -110,6 +178,7 @@ static struct option longopts[] = { "time", no_argument, &dotest, 3 }, { "fexport",no_argument, &dotest, 4 }, { "textbl", no_argument, &dotest, 5 }, + { "texi", no_argument, &dotest, 6 }, { "thread", required_argument, NULL, 't' }, { "verbose",no_argument, &verbose, 1 }, @@ -149,6 +218,7 @@ void usage() "--mgl - use MGL scripts for samples\n" "--test - run in test mode\n" "--time - measure execution time for all samples\n" + "--texi - make TeXi file with all samples\n" "--font - write current font as C++ file\n" "--quality=val - use specified quality for plot(s)\n" "--fexport - test most of output formats\n" @@ -171,7 +241,7 @@ void save(mglGraph *gr,const char *name,const char *suf="") case 3: // PNG snprintf(buf,128,"%s%s.png",name,suf); gr->WritePNG(buf,0,true); break; - case 4: // JPEG + case 4: // JPEG/* r1 = 1./(x*x+y*y+z*z+0.01); r2=exp(-0.01/r1/r1)*r1; snprintf(buf,128,"%s%s.jpg",name,suf); gr->WriteJPEG(buf); break; case 5: // PRC @@ -229,165 +299,14 @@ void save(mglGraph *gr,const char *name,const char *suf="") } } //----------------------------------------------------------------------------- -void smgl_fexport(mglGraph *gr) // test file export -{ - gr->SubPlot(3,2,0); - double d,x1,x2,x0,y=0.95; - d=0.3, x0=0.2, x1=0.5, x2=0.6; - gr->Line(mglPoint(x0,1-0*d),mglPoint(x1,1-0*d),"k-"); gr->Puts(mglPoint(x2,y-0*d),"Solid '-'",":rL"); - gr->Line(mglPoint(x0,1-1*d),mglPoint(x1,1-1*d),"k|"); gr->Puts(mglPoint(x2,y-1*d),"Long Dash '|'",":rL"); - gr->Line(mglPoint(x0,1-2*d),mglPoint(x1,1-2*d),"k;"); gr->Puts(mglPoint(x2,y-2*d),"Dash ';'",":rL"); - gr->Line(mglPoint(x0,1-3*d),mglPoint(x1,1-3*d),"k="); gr->Puts(mglPoint(x2,y-3*d),"Small dash '='",":rL"); - gr->Line(mglPoint(x0,1-4*d),mglPoint(x1,1-4*d),"kj"); gr->Puts(mglPoint(x2,y-4*d),"Dash-dot 'j'",":rL"); - gr->Line(mglPoint(x0,1-5*d),mglPoint(x1,1-5*d),"ki"); gr->Puts(mglPoint(x2,y-5*d),"Small dash-dot 'i'",":rL"); - gr->Line(mglPoint(x0,1-6*d),mglPoint(x1,1-6*d),"k:"); gr->Puts(mglPoint(x2,y-6*d),"Dots ':'",":rL"); - gr->Line(mglPoint(x0,1-7*d),mglPoint(x1,1-7*d),"k "); gr->Puts(mglPoint(x2,y-7*d),"None ' '",":rL"); - - d=0.25; x1=-1; x0=-0.8; y = -0.05; - gr->Mark(mglPoint(x1,5*d),"k."); gr->Puts(mglPoint(x0,y+5*d),"'.'",":rL"); - gr->Mark(mglPoint(x1,4*d),"k+"); gr->Puts(mglPoint(x0,y+4*d),"'+'",":rL"); - gr->Mark(mglPoint(x1,3*d),"kx"); gr->Puts(mglPoint(x0,y+3*d),"'x'",":rL"); - gr->Mark(mglPoint(x1,2*d),"k*"); gr->Puts(mglPoint(x0,y+2*d),"'*'",":rL"); - gr->Mark(mglPoint(x1,d),"ks"); gr->Puts(mglPoint(x0,y+d),"'s'",":rL"); - gr->Mark(mglPoint(x1,0),"kd"); gr->Puts(mglPoint(x0,y),"'d'",":rL"); - gr->Mark(mglPoint(x1,-d,0),"ko"); gr->Puts(mglPoint(x0,y-d),"'o'",":rL"); - gr->Mark(mglPoint(x1,-2*d,0),"k^"); gr->Puts(mglPoint(x0,y-2*d),"'\\^'",":rL"); - gr->Mark(mglPoint(x1,-3*d,0),"kv"); gr->Puts(mglPoint(x0,y-3*d),"'v'",":rL"); - gr->Mark(mglPoint(x1,-4*d,0),"k<"); gr->Puts(mglPoint(x0,y-4*d),"'<'",":rL"); - gr->Mark(mglPoint(x1,-5*d,0),"k>"); gr->Puts(mglPoint(x0,y-5*d),"'>'",":rL"); - - d=0.25; x1=-0.5; x0=-0.3; y = -0.05; - gr->Mark(mglPoint(x1,5*d),"k#."); gr->Puts(mglPoint(x0,y+5*d),"'\\#.'",":rL"); - gr->Mark(mglPoint(x1,4*d),"k#+"); gr->Puts(mglPoint(x0,y+4*d),"'\\#+'",":rL"); - gr->Mark(mglPoint(x1,3*d),"k#x"); gr->Puts(mglPoint(x0,y+3*d),"'\\#x'",":rL"); - gr->Mark(mglPoint(x1,2*d),"k#*"); gr->Puts(mglPoint(x0,y+2*d),"'\\#*'",":rL"); - gr->Mark(mglPoint(x1,d),"k#s"); gr->Puts(mglPoint(x0,y+d),"'\\#s'",":rL"); - gr->Mark(mglPoint(x1,0),"k#d"); gr->Puts(mglPoint(x0,y),"'\\#d'",":rL"); - gr->Mark(mglPoint(x1,-d,0),"k#o"); gr->Puts(mglPoint(x0,y-d),"'\\#o'",":rL"); - gr->Mark(mglPoint(x1,-2*d,0),"k#^"); gr->Puts(mglPoint(x0,y-2*d),"'\\#\\^'",":rL"); - gr->Mark(mglPoint(x1,-3*d,0),"k#v"); gr->Puts(mglPoint(x0,y-3*d),"'\\#v'",":rL"); - gr->Mark(mglPoint(x1,-4*d,0),"k#<"); gr->Puts(mglPoint(x0,y-4*d),"'\\#<'",":rL"); - gr->Mark(mglPoint(x1,-5*d,0),"k#>"); gr->Puts(mglPoint(x0,y-5*d),"'\\#>'",":rL"); - - gr->SubPlot(3,2,1); - double a=0.1,b=0.4,c=0.5; - gr->Line(mglPoint(a,1),mglPoint(b,1),"k-A"); gr->Puts(mglPoint(c,1),"Style 'A' or 'A\\_'",":rL"); - gr->Line(mglPoint(a,0.8),mglPoint(b,0.8),"k-V"); gr->Puts(mglPoint(c,0.8),"Style 'V' or 'V\\_'",":rL"); - gr->Line(mglPoint(a,0.6),mglPoint(b,0.6),"k-K"); gr->Puts(mglPoint(c,0.6),"Style 'K' or 'K\\_'",":rL"); - gr->Line(mglPoint(a,0.4),mglPoint(b,0.4),"k-I"); gr->Puts(mglPoint(c,0.4),"Style 'I' or 'I\\_'",":rL"); - gr->Line(mglPoint(a,0.2),mglPoint(b,0.2),"k-D"); gr->Puts(mglPoint(c,0.2),"Style 'D' or 'D\\_'",":rL"); - gr->Line(mglPoint(a,0),mglPoint(b,0),"k-S"); gr->Puts(mglPoint(c,0),"Style 'S' or 'S\\_'",":rL"); - gr->Line(mglPoint(a,-0.2),mglPoint(b,-0.2),"k-O"); gr->Puts(mglPoint(c,-0.2),"Style 'O' or 'O\\_'",":rL"); - gr->Line(mglPoint(a,-0.4),mglPoint(b,-0.4),"k-T"); gr->Puts(mglPoint(c,-0.4),"Style 'T' or 'T\\_'",":rL"); - gr->Line(mglPoint(a,-0.6),mglPoint(b,-0.6),"k-_"); gr->Puts(mglPoint(c,-0.6),"Style '\\_' or none",":rL"); - gr->Line(mglPoint(a,-0.8),mglPoint(b,-0.8),"k-AS"); gr->Puts(mglPoint(c,-0.8),"Style 'AS'",":rL"); - gr->Line(mglPoint(a,-1),mglPoint(b,-1),"k-_A"); gr->Puts(mglPoint(c,-1),"Style '\\_A'",":rL"); - - a=-1; b=-0.7; c=-0.6; - gr->Line(mglPoint(a,1),mglPoint(b,1),"kAA"); gr->Puts(mglPoint(c,1),"Style 'AA'",":rL"); - gr->Line(mglPoint(a,0.8),mglPoint(b,0.8),"kVV"); gr->Puts(mglPoint(c,0.8),"Style 'VV'",":rL"); - gr->Line(mglPoint(a,0.6),mglPoint(b,0.6),"kKK"); gr->Puts(mglPoint(c,0.6),"Style 'KK'",":rL"); - gr->Line(mglPoint(a,0.4),mglPoint(b,0.4),"kII"); gr->Puts(mglPoint(c,0.4),"Style 'II'",":rL"); - gr->Line(mglPoint(a,0.2),mglPoint(b,0.2),"kDD"); gr->Puts(mglPoint(c,0.2),"Style 'DD'",":rL"); - gr->Line(mglPoint(a,0),mglPoint(b,0),"kSS"); gr->Puts(mglPoint(c,0),"Style 'SS'",":rL"); - gr->Line(mglPoint(a,-0.2),mglPoint(b,-0.2),"kOO"); gr->Puts(mglPoint(c,-0.2),"Style 'OO'",":rL"); - gr->Line(mglPoint(a,-0.4),mglPoint(b,-0.4),"kTT"); gr->Puts(mglPoint(c,-0.4),"Style 'TT'",":rL"); - gr->Line(mglPoint(a,-0.6),mglPoint(b,-0.6),"k-__"); gr->Puts(mglPoint(c,-0.6),"Style '\\_\\_'",":rL"); - gr->Line(mglPoint(a,-0.8),mglPoint(b,-0.8),"k-VA"); gr->Puts(mglPoint(c,-0.8),"Style 'VA'",":rL"); - gr->Line(mglPoint(a,-1),mglPoint(b,-1),"k-AV"); gr->Puts(mglPoint(c,-1),"Style 'AV'",":rL"); - - gr->SubPlot(3,2,2); - //#LENUQ - gr->FaceZ(mglPoint(-1, -1), 0.4, 0.3, "L#"); gr->Puts(mglPoint(-0.8,-0.9), "L", "w:C", -1.4); - gr->FaceZ(mglPoint(-0.6,-1), 0.4, 0.3, "E#"); gr->Puts(mglPoint(-0.4,-0.9), "E", "w:C", -1.4); - gr->FaceZ(mglPoint(-0.2,-1), 0.4, 0.3, "N#"); gr->Puts(mglPoint(0, -0.9), "N", "w:C", -1.4); - gr->FaceZ(mglPoint(0.2, -1), 0.4, 0.3, "U#"); gr->Puts(mglPoint(0.4,-0.9), "U", "w:C", -1.4); - gr->FaceZ(mglPoint(0.6, -1), 0.4, 0.3, "Q#"); gr->Puts(mglPoint(0.8,-0.9), "Q", "w:C", -1.4); - //#lenuq - gr->FaceZ(mglPoint(-1, -0.7), 0.4, 0.3, "l#"); gr->Puts(mglPoint(-0.8,-0.6), "l", "k:C", -1.4); - gr->FaceZ(mglPoint(-0.6,-0.7), 0.4, 0.3, "e#"); gr->Puts(mglPoint(-0.4,-0.6), "e", "k:C", -1.4); - gr->FaceZ(mglPoint(-0.2,-0.7), 0.4, 0.3, "n#"); gr->Puts(mglPoint(0, -0.6), "n", "k:C", -1.4); - gr->FaceZ(mglPoint(0.2, -0.7), 0.4, 0.3, "u#"); gr->Puts(mglPoint(0.4,-0.6), "u", "k:C", -1.4); - gr->FaceZ(mglPoint(0.6, -0.7), 0.4, 0.3, "q#"); gr->Puts(mglPoint(0.8,-0.6), "q", "k:C", -1.4); - //#CMYkP - gr->FaceZ(mglPoint(-1, -0.4), 0.4, 0.3, "C#"); gr->Puts(mglPoint(-0.8,-0.3), "C", "w:C", -1.4); - gr->FaceZ(mglPoint(-0.6,-0.4), 0.4, 0.3, "M#"); gr->Puts(mglPoint(-0.4,-0.3), "M", "w:C", -1.4); - gr->FaceZ(mglPoint(-0.2,-0.4), 0.4, 0.3, "Y#"); gr->Puts(mglPoint(0, -0.3), "Y", "w:C", -1.4); - gr->FaceZ(mglPoint(0.2, -0.4), 0.4, 0.3, "k#"); gr->Puts(mglPoint(0.4,-0.3), "k", "w:C", -1.4); - gr->FaceZ(mglPoint(0.6, -0.4), 0.4, 0.3, "P#"); gr->Puts(mglPoint(0.8,-0.3), "P", "w:C", -1.4); - //#cmywp - gr->FaceZ(mglPoint(-1, -0.1), 0.4, 0.3, "c#"); gr->Puts(mglPoint(-0.8, 0), "c", "k:C", -1.4); - gr->FaceZ(mglPoint(-0.6,-0.1), 0.4, 0.3, "m#"); gr->Puts(mglPoint(-0.4, 0), "m", "k:C", -1.4); - gr->FaceZ(mglPoint(-0.2,-0.1), 0.4, 0.3, "y#"); gr->Puts(mglPoint(0, 0), "y", "k:C", -1.4); - gr->FaceZ(mglPoint(0.2, -0.1), 0.4, 0.3, "w#"); gr->Puts(mglPoint(0.4, 0), "w", "k:C", -1.4); - gr->FaceZ(mglPoint(0.6, -0.1), 0.4, 0.3, "p#"); gr->Puts(mglPoint(0.8, 0), "p", "k:C", -1.4); - //#BGRHW - gr->FaceZ(mglPoint(-1, 0.2), 0.4, 0.3, "B#"); gr->Puts(mglPoint(-0.8, 0.3), "B", "w:C", -1.4); - gr->FaceZ(mglPoint(-0.6,0.2), 0.4, 0.3, "G#"); gr->Puts(mglPoint(-0.4, 0.3), "G", "w:C", -1.4); - gr->FaceZ(mglPoint(-0.2,0.2), 0.4, 0.3, "R#"); gr->Puts(mglPoint(0, 0.3), "R", "w:C", -1.4); - gr->FaceZ(mglPoint(0.2, 0.2), 0.4, 0.3, "H#"); gr->Puts(mglPoint(0.4, 0.3), "H", "w:C", -1.4); - gr->FaceZ(mglPoint(0.6, 0.2), 0.4, 0.3, "W#"); gr->Puts(mglPoint(0.8, 0.3), "W", "w:C", -1.4); - //#bgrhw - gr->FaceZ(mglPoint(-1, 0.5), 0.4, 0.3, "b#"); gr->Puts(mglPoint(-0.8, 0.6), "b", "k:C", -1.4); - gr->FaceZ(mglPoint(-0.6,0.5), 0.4, 0.3, "g#"); gr->Puts(mglPoint(-0.4, 0.6), "g", "k:C", -1.4); - gr->FaceZ(mglPoint(-0.2,0.5), 0.4, 0.3, "r#"); gr->Puts(mglPoint(0, 0.6), "r", "k:C", -1.4); - gr->FaceZ(mglPoint(0.2, 0.5), 0.4, 0.3, "h#"); gr->Puts(mglPoint(0.4, 0.6), "h", "k:C", -1.4); - gr->FaceZ(mglPoint(0.6, 0.5), 0.4, 0.3, "w#"); gr->Puts(mglPoint(0.8, 0.6), "w", "k:C", -1.4); - //#brighted - gr->FaceZ(mglPoint(-1, 0.8), 0.4, 0.3, "{r1}#"); gr->Puts(mglPoint(-0.8, 0.9), "\\{r1\\}", "w:C", -1.4); - gr->FaceZ(mglPoint(-0.6,0.8), 0.4, 0.3, "{r3}#"); gr->Puts(mglPoint(-0.4, 0.9), "\\{r3\\}", "w:C", -1.4); - gr->FaceZ(mglPoint(-0.2,0.8), 0.4, 0.3, "{r5}#"); gr->Puts(mglPoint(0, 0.9), "\\{r5\\}", "k:C", -1.4); - gr->FaceZ(mglPoint(0.2, 0.8), 0.4, 0.3, "{r7}#"); gr->Puts(mglPoint(0.4, 0.9), "\\{r7\\}", "k:C", -1.4); - gr->FaceZ(mglPoint(0.6, 0.8), 0.4, 0.3, "{r9}#"); gr->Puts(mglPoint(0.8, 0.9), "\\{r9\\}", "k:C", -1.4); - // HEX - gr->FaceZ(mglPoint(-1, -1.3), 1, 0.3, "{xff9966}#"); gr->Puts(mglPoint(-0.5,-1.2), "\\{xff9966\\}", "k:C", -1.4); - gr->FaceZ(mglPoint(0, -1.3), 1, 0.3, "{x83CAFF}#"); gr->Puts(mglPoint( 0.5,-1.2), "\\{x83CAFF\\}", "k:C", -1.4); - - gr->SubPlot(3,2,3); - char stl[3]="r1", txt[4]="'1'"; - for(int i=0;i<10;i++) - { - txt[1]=stl[1]='0'+i; - gr->Line(mglPoint(-1,0.2*i-1),mglPoint(1,0.2*i-1),stl); - gr->Puts(mglPoint(1.05,0.2*i-1),txt,":L"); - } - - gr->SubPlot(3,2,4); gr->Title("TriPlot sample"); gr->Rotate(50,60); - double t[] = {0,1,2, 0,1,3, 0,2,3, 1,2,3}; - double 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->TriPlot(tt,uu,vv,ww,"b"); - gr->TriPlot(tt,uu,vv,ww,"k#"); - - gr->SubPlot(3,2,5); - mglData r(4); r.Fill(1,4); - gr->SetRanges(1,4,1,4); gr->Axis(); - gr->Mark(r,r,"s"); - gr->Plot(r,"b"); - - gr->WriteJPEG("fexport.jpg"); -// gr->WritePNG("fexport.png"); - gr->WriteBMP("fexport.bmp"); - gr->WriteTGA("fexport.tga"); - gr->WriteEPS("fexport.eps"); - gr->WriteSVG("fexport.svg"); - gr->WriteGIF("fexport.gif"); - - gr->WriteXYZ("fexport.xyz"); - gr->WriteSTL("fexport.stl"); - gr->WriteOFF("fexport.off"); - gr->WriteTEX("fexport.tex"); - gr->WriteOBJ("fexport.obj"); - gr->WritePRC("fexport.prc"); - gr->WriteJSON("fexport.json"); - - gr->ExportMGLD("fexport.mgld"); - gr->Clf(); - gr->ImportMGLD("fexport.mgld"); -} -//----------------------------------------------------------------------------- int main(int argc,char **argv) { +// const char *f = strrchr(argv[0],'/'); +// std::string p(argv[0],f-argv[0]); +// printf("getcwd = '%s', argv = '%s', path = '%s', inst = '%s'\n", getcwd(NULL,0), argv[0], p.c_str(), MGL_INSTALL_DIR); +// fflush(stdout); + + mgl_textdomain(argv?argv[0]:NULL,""); mgl_suppress_warn(true); const char *suf = ""; char name[256]="", *tmp; @@ -402,7 +321,7 @@ int main(int argc,char **argv) case 'w': width =atoi(optarg); break; case 'h': height=atoi(optarg); break; case 'q': quality =atoi(optarg); break; - case 'k': strncpy(name, optarg,256); + case 'k': mgl_strncpy(name, optarg,256); tmp=strchr(name,'.'); if(tmp) *tmp=0; tmp=strchr(name,'-'); if(tmp) *tmp=0; break; @@ -442,7 +361,6 @@ int main(int argc,char **argv) delete gr; return 0; } else if(dotest==2) // NOTE mgl_gen_fnt[###][6] have to be updated if new glyphs will be added to built-in font - { mgl_create_cpp_font(gr->Self(), L"!-~,¡-ÿ,̀-̏,Α-ω,ϑ,ϕ,ϖ,ϰ,ϱ,ϵ,А-я,ℏ,ℑ,ℓ,ℜ,←-↙,∀-∯,≠-≯,⟂"); delete gr; return 0; } else if(dotest==3) @@ -450,8 +368,18 @@ int main(int argc,char **argv) int qual[7]={0,1,2,4,5,6,8}; size_t ll=strlen(mmgl_dat_prepare)+1; mglParse par; - par.AllowSetSize(true); setlocale(LC_CTYPE, ""); + par.AllowSetSize(true); FILE *fp = fopen(big?"time_big.texi":"time.texi","w"); + FILE *fi = fopen("/proc/cpuinfo","r"); + if(fi) + { + char buf[128]; + while(!feof(fi)) + { fgets(buf,128,fi); + if(!strstr(buf,"model name")) + { fprintf(fp,"@c %s\n",buf); break; } } + fclose(fi); + } fprintf(fp,"@multitable @columnfractions .16 .12 .12 .12 .12 .12 .12 .12\n"); fprintf(fp,"@headitem Name"); for(int i=0;i<7;i++) fprintf(fp," @tab q=%d",qual[i]); @@ -487,6 +415,11 @@ int main(int argc,char **argv) mgl_check_tex_table(); delete gr; return 0; } + else if(dotest==6) + { + mgl_generate_texi(); + delete gr; return 0; + } if(type==15 || type==16) big=3; // save mini version for json @@ -501,7 +434,6 @@ int main(int argc,char **argv) { mglParse par; par.AllowSetSize(true); - setlocale(LC_CTYPE, ""); char *buf = new char[strlen(s->mgl)+strlen(mmgl_dat_prepare)+1]; strcpy(buf,s->mgl); strcat(buf,mmgl_dat_prepare); if(type!=7) printf("\n-------\n%s\n-------\n",verbose?buf:s->mgl); @@ -512,6 +444,7 @@ int main(int argc,char **argv) else s->func(gr); save(gr, s->name, suf); printf("%s ",s->name); fflush(stdout); s++; + gr->SetQuality(quality); } printf("\n"); } @@ -528,7 +461,6 @@ int main(int argc,char **argv) { mglParse par; par.AllowSetSize(true); - setlocale(LC_CTYPE, ""); char *buf = new char[strlen(s->mgl)+strlen(mmgl_dat_prepare)+1]; strcpy(buf,s->mgl); strcat(buf,mmgl_dat_prepare); if(type!=7) printf("\n-------\n%s\n-------\n",verbose?buf:s->mgl); diff --git a/examples/glut_example.cpp b/examples/glut_example.cpp index c921583..07a70f5 100644 --- a/examples/glut_example.cpp +++ b/examples/glut_example.cpp @@ -56,6 +56,7 @@ printf("i=%d, gr=%p\n",i,gr); fflush(stdout); } int main(int argc,char **argv) { + mgl_textdomain(argv?argv[0]:NULL); static pthread_t thr; pthread_create(&thr,0,calc,0); pthread_detach(thr); @@ -75,6 +76,7 @@ int sample_d(mglGraph *gr); typedef int (*draw_func)(mglGraph *gr); int main(int argc,char **argv) { + mgl_textdomain(argv?argv[0]:NULL,""); char key = 0; if(argc>1) key = argv[1][0]!='-' ? argv[1][0] : argv[1][1]; else printf("You may specify argument '1', '2', '3' or 'd' for viewing examples of 1d, 2d, 3d or dual plotting\n"); @@ -89,4 +91,4 @@ int main(int argc,char **argv) } return 0; } -#endif \ No newline at end of file +#endif diff --git a/examples/iris.dat b/examples/iris.dat new file mode 100644 index 0000000..5c4316c --- /dev/null +++ b/examples/iris.dat @@ -0,0 +1,151 @@ +5.1,3.5,1.4,0.2,Iris-setosa +4.9,3.0,1.4,0.2,Iris-setosa +4.7,3.2,1.3,0.2,Iris-setosa +4.6,3.1,1.5,0.2,Iris-setosa +5.0,3.6,1.4,0.2,Iris-setosa +5.4,3.9,1.7,0.4,Iris-setosa +4.6,3.4,1.4,0.3,Iris-setosa +5.0,3.4,1.5,0.2,Iris-setosa +4.4,2.9,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +5.4,3.7,1.5,0.2,Iris-setosa +4.8,3.4,1.6,0.2,Iris-setosa +4.8,3.0,1.4,0.1,Iris-setosa +4.3,3.0,1.1,0.1,Iris-setosa +5.8,4.0,1.2,0.2,Iris-setosa +5.7,4.4,1.5,0.4,Iris-setosa +5.4,3.9,1.3,0.4,Iris-setosa +5.1,3.5,1.4,0.3,Iris-setosa +5.7,3.8,1.7,0.3,Iris-setosa +5.1,3.8,1.5,0.3,Iris-setosa +5.4,3.4,1.7,0.2,Iris-setosa +5.1,3.7,1.5,0.4,Iris-setosa +4.6,3.6,1.0,0.2,Iris-setosa +5.1,3.3,1.7,0.5,Iris-setosa +4.8,3.4,1.9,0.2,Iris-setosa +5.0,3.0,1.6,0.2,Iris-setosa +5.0,3.4,1.6,0.4,Iris-setosa +5.2,3.5,1.5,0.2,Iris-setosa +5.2,3.4,1.4,0.2,Iris-setosa +4.7,3.2,1.6,0.2,Iris-setosa +4.8,3.1,1.6,0.2,Iris-setosa +5.4,3.4,1.5,0.4,Iris-setosa +5.2,4.1,1.5,0.1,Iris-setosa +5.5,4.2,1.4,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +5.0,3.2,1.2,0.2,Iris-setosa +5.5,3.5,1.3,0.2,Iris-setosa +4.9,3.1,1.5,0.1,Iris-setosa +4.4,3.0,1.3,0.2,Iris-setosa +5.1,3.4,1.5,0.2,Iris-setosa +5.0,3.5,1.3,0.3,Iris-setosa +4.5,2.3,1.3,0.3,Iris-setosa +4.4,3.2,1.3,0.2,Iris-setosa +5.0,3.5,1.6,0.6,Iris-setosa +5.1,3.8,1.9,0.4,Iris-setosa +4.8,3.0,1.4,0.3,Iris-setosa +5.1,3.8,1.6,0.2,Iris-setosa +4.6,3.2,1.4,0.2,Iris-setosa +5.3,3.7,1.5,0.2,Iris-setosa +5.0,3.3,1.4,0.2,Iris-setosa +7.0,3.2,4.7,1.4,Iris-versicolor +6.4,3.2,4.5,1.5,Iris-versicolor +6.9,3.1,4.9,1.5,Iris-versicolor +5.5,2.3,4.0,1.3,Iris-versicolor +6.5,2.8,4.6,1.5,Iris-versicolor +5.7,2.8,4.5,1.3,Iris-versicolor +6.3,3.3,4.7,1.6,Iris-versicolor +4.9,2.4,3.3,1.0,Iris-versicolor +6.6,2.9,4.6,1.3,Iris-versicolor +5.2,2.7,3.9,1.4,Iris-versicolor +5.0,2.0,3.5,1.0,Iris-versicolor +5.9,3.0,4.2,1.5,Iris-versicolor +6.0,2.2,4.0,1.0,Iris-versicolor +6.1,2.9,4.7,1.4,Iris-versicolor +5.6,2.9,3.6,1.3,Iris-versicolor +6.7,3.1,4.4,1.4,Iris-versicolor +5.6,3.0,4.5,1.5,Iris-versicolor +5.8,2.7,4.1,1.0,Iris-versicolor +6.2,2.2,4.5,1.5,Iris-versicolor +5.6,2.5,3.9,1.1,Iris-versicolor +5.9,3.2,4.8,1.8,Iris-versicolor +6.1,2.8,4.0,1.3,Iris-versicolor +6.3,2.5,4.9,1.5,Iris-versicolor +6.1,2.8,4.7,1.2,Iris-versicolor +6.4,2.9,4.3,1.3,Iris-versicolor +6.6,3.0,4.4,1.4,Iris-versicolor +6.8,2.8,4.8,1.4,Iris-versicolor +6.7,3.0,5.0,1.7,Iris-versicolor +6.0,2.9,4.5,1.5,Iris-versicolor +5.7,2.6,3.5,1.0,Iris-versicolor +5.5,2.4,3.8,1.1,Iris-versicolor +5.5,2.4,3.7,1.0,Iris-versicolor +5.8,2.7,3.9,1.2,Iris-versicolor +6.0,2.7,5.1,1.6,Iris-versicolor +5.4,3.0,4.5,1.5,Iris-versicolor +6.0,3.4,4.5,1.6,Iris-versicolor +6.7,3.1,4.7,1.5,Iris-versicolor +6.3,2.3,4.4,1.3,Iris-versicolor +5.6,3.0,4.1,1.3,Iris-versicolor +5.5,2.5,4.0,1.3,Iris-versicolor +5.5,2.6,4.4,1.2,Iris-versicolor +6.1,3.0,4.6,1.4,Iris-versicolor +5.8,2.6,4.0,1.2,Iris-versicolor +5.0,2.3,3.3,1.0,Iris-versicolor +5.6,2.7,4.2,1.3,Iris-versicolor +5.7,3.0,4.2,1.2,Iris-versicolor +5.7,2.9,4.2,1.3,Iris-versicolor +6.2,2.9,4.3,1.3,Iris-versicolor +5.1,2.5,3.0,1.1,Iris-versicolor +5.7,2.8,4.1,1.3,Iris-versicolor +6.3,3.3,6.0,2.5,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +7.1,3.0,5.9,2.1,Iris-virginica +6.3,2.9,5.6,1.8,Iris-virginica +6.5,3.0,5.8,2.2,Iris-virginica +7.6,3.0,6.6,2.1,Iris-virginica +4.9,2.5,4.5,1.7,Iris-virginica +7.3,2.9,6.3,1.8,Iris-virginica +6.7,2.5,5.8,1.8,Iris-virginica +7.2,3.6,6.1,2.5,Iris-virginica +6.5,3.2,5.1,2.0,Iris-virginica +6.4,2.7,5.3,1.9,Iris-virginica +6.8,3.0,5.5,2.1,Iris-virginica +5.7,2.5,5.0,2.0,Iris-virginica +5.8,2.8,5.1,2.4,Iris-virginica +6.4,3.2,5.3,2.3,Iris-virginica +6.5,3.0,5.5,1.8,Iris-virginica +7.7,3.8,6.7,2.2,Iris-virginica +7.7,2.6,6.9,2.3,Iris-virginica +6.0,2.2,5.0,1.5,Iris-virginica +6.9,3.2,5.7,2.3,Iris-virginica +5.6,2.8,4.9,2.0,Iris-virginica +7.7,2.8,6.7,2.0,Iris-virginica +6.3,2.7,4.9,1.8,Iris-virginica +6.7,3.3,5.7,2.1,Iris-virginica +7.2,3.2,6.0,1.8,Iris-virginica +6.2,2.8,4.8,1.8,Iris-virginica +6.1,3.0,4.9,1.8,Iris-virginica +6.4,2.8,5.6,2.1,Iris-virginica +7.2,3.0,5.8,1.6,Iris-virginica +7.4,2.8,6.1,1.9,Iris-virginica +7.9,3.8,6.4,2.0,Iris-virginica +6.4,2.8,5.6,2.2,Iris-virginica +6.3,2.8,5.1,1.5,Iris-virginica +6.1,2.6,5.6,1.4,Iris-virginica +7.7,3.0,6.1,2.3,Iris-virginica +6.3,3.4,5.6,2.4,Iris-virginica +6.4,3.1,5.5,1.8,Iris-virginica +6.0,3.0,4.8,1.8,Iris-virginica +6.9,3.1,5.4,2.1,Iris-virginica +6.7,3.1,5.6,2.4,Iris-virginica +6.9,3.1,5.1,2.3,Iris-virginica +5.8,2.7,5.1,1.9,Iris-virginica +6.8,3.2,5.9,2.3,Iris-virginica +6.7,3.3,5.7,2.5,Iris-virginica +6.7,3.0,5.2,2.3,Iris-virginica +6.3,2.5,5.0,1.9,Iris-virginica +6.5,3.0,5.2,2.0,Iris-virginica +6.2,3.4,5.4,2.3,Iris-virginica +5.9,3.0,5.1,1.8,Iris-virginica + diff --git a/examples/mgl_module.cpp b/examples/mgl_module.cpp index 34ecf67..e741964 100644 --- a/examples/mgl_module.cpp +++ b/examples/mgl_module.cpp @@ -6,8 +6,9 @@ int test1(mglGraph *gr, long , mglArg *a, const char *k, const char *) { int res=0; if(!strcmp(k,"")) { gr->Box(); gr->Axis(); } - else if(!strcmp(k,"s")) { gr->Box(); gr->Axis(a[0].s.c_str()); } - else res = 1; return res; + else if(!strcmp(k,"s")) { gr->Box(); gr->Axis(a[0].s.s); } + else res = 1; + return res; } //----------------------------------------------------------------------------- int test2(mglGraph *gr, long , mglArg *a, const char *k, const char *) @@ -16,14 +17,15 @@ int test2(mglGraph *gr, long , mglArg *a, const char *k, const char *) if(!strcmp(k,"nnnns")) { gr->FaceZ(mglPoint(a[0].v-a[2].v/2,a[1].v-a[3].v/2),a[2].v,a[3].v,"r"); - gr->Putsw(mglPoint(a[0].v,a[1].v),a[4].w.c_str()); + gr->Putsw(mglPoint(a[0].v,a[1].v),a[4].s.w); } else if(!strcmp(k,"nnnnss")) { - gr->FaceZ(mglPoint(a[0].v-a[2].v/2,a[1].v-a[3].v/2),a[2].v,a[3].v,a[5].s.c_str()); - gr->Putsw(mglPoint(a[0].v,a[1].v),a[4].w.c_str()); + gr->FaceZ(mglPoint(a[0].v-a[2].v/2,a[1].v-a[3].v/2),a[2].v,a[3].v,a[5].s.s); + gr->Putsw(mglPoint(a[0].v,a[1].v),a[4].s.w); } - else res = 1; return res; + else res = 1; + return res; } //----------------------------------------------------------------------------- mglCommand mgl_cmd_extra[] = { diff --git a/examples/mpi_test.cpp b/examples/mpi_test.cpp index 74865f7..1f8d982 100644 --- a/examples/mpi_test.cpp +++ b/examples/mpi_test.cpp @@ -4,6 +4,7 @@ int main(int argc, char *argv[]) { + mgl_textdomain(argv?argv[0]:NULL,""); // initialize MPI int rank=0, numproc=1; MPI_Init(&argc, &argv); diff --git a/examples/qgl_example.cpp b/examples/qgl_example.cpp index 77fa94b..b0f0d5c 100644 --- a/examples/qgl_example.cpp +++ b/examples/qgl_example.cpp @@ -23,6 +23,7 @@ //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { + mgl_textdomain(argv?argv[0]:NULL,""); QApplication a(argc, argv); MainWindow w; w.show(); @@ -42,7 +43,8 @@ void MainWindow::initializeGL() void MainWindow::paintGL() { gr->Clf(); - gr->Rotate(40,5); + gr->SubPlot(1,1,0); + gr->Rotate(40,60); gr->Light(true); gr->AddLight(0,mglPoint(0,0,10),mglPoint(0,0,-1)); gr->Axis(); diff --git a/examples/qt_example.cpp b/examples/qt_example.cpp index 7d5e4ab..c27b101 100644 --- a/examples/qt_example.cpp +++ b/examples/qt_example.cpp @@ -55,6 +55,7 @@ void *calc(void *) } int main(int argc,char **argv) { + mgl_textdomain(argv?argv[0]:NULL); static pthread_t thr; pthread_create(&thr,0,calc,0); pthread_detach(thr); @@ -87,6 +88,7 @@ int Foo::Draw(mglGraph *gr) } int main(int argc,char **argv) { + mgl_textdomain(argv?argv[0]:NULL); Foo *foo = new Foo; mglQT gr(foo,"MathGL examples"); foo->Gr = &gr; @@ -109,7 +111,7 @@ class myDraw : public mglDraw long i; // another variable to be shown mglWnd *wnd; // external window for plotting public: - myDraw(mglWnd *w=0) : mglDraw() { wnd=w; } + myDraw(mglWnd *w=0) : mglDraw() { wnd=w; i=0; } void SetWnd(mglWnd *w) { wnd=w; } int Draw(mglGraph *gr) { @@ -133,6 +135,7 @@ public: //----------------------------------------------------------------------------- int main(int argc,char **argv) { + mgl_textdomain(argv?argv[0]:NULL,""); mglQT *gr; char key = 0; if(argc>1) key = argv[1][0]!='-' ? argv[1][0]:argv[1][1]; diff --git a/examples/samples.cpp b/examples/samples.cpp index 243f59a..3114c8a 100644 --- a/examples/samples.cpp +++ b/examples/samples.cpp @@ -31,11 +31,12 @@ struct mglSample /// Structure for list of samples const char *name; void (*func)(mglGraph*); const char *mgl; + const char *info; }; //----------------------------------------------------------------------------- // MGL functions for preparing data //----------------------------------------------------------------------------- -const char *mmgl_dat_prepare = "\nstop\n\nfunc 'prepare1d'\n\ +const char *mmgl_dat_prepare = "\nfunc 'prepare1d'\n\ new y 50 3\nmodify y '0.7*sin(2*pi*x)+0.5*cos(3*pi*x)+0.2*sin(pi*x)'\n\ modify y 'sin(2*pi*x)' 1\nmodify y 'cos(2*pi*x)' 2\n\ new x1 50 'x'\nnew x2 50 '0.05-0.03*cos(pi*x)'\n\ @@ -754,8 +755,9 @@ const char *mmgl_text="call 'prepare1d'\nsubplot 2 2 0 ''\ntext 0 1 'Text can be "text 0 -0.6 'Easy to change indexes ^{up} _{down} @{center}'\n" "text 0 -1 'It parse TeX: \\int \\alpha \\cdot \\\n\\sqrt3{sin(\\pi x)^2 + \\gamma_{i_k}} dx'\n" "subplot 2 2 1 ''\n text 0 0.5 '\\sqrt{\\frac{\\alpha^{\\gamma^2}+\\overset 1{\\big\\infty}}{\\sqrt3{2+b}}}' '@' -2\n" -"text 0 -0.3 'Text can be printed\\n{}on several lines'\n" -"text 0 -0.7 'or with color gradient' 'BbcyrR'\n" +"text 0 -0.1 'More text position: \\frac{a}{b}, \\dfrac{a}{b}, [\\stack{a}{bbb}], [\\stackl{a}{bbb}], [\\stackr{a}{bbb}], \\sup{a}{sup}, \\sub{a}{sub}'" +"text 0 -0.5 'Text can be printed\\n{}on several lines'\n" +"text 0 -0.9 'or with color gradient' 'BbcyrR'\n" "subplot 2 2 2 '':box:plot y(:,0)\ntext y 'This is very very long string drawn along a curve' 'k'\ntext y 'Another string drawn above a curve' 'Tr'\n" "subplot 2 2 3 '':line -1 -1 1 -1 'rA':text 0 -1 1 -1 'Horizontal'\n" "line -1 -1 1 1 'rA':text 0 0 1 1 'At angle' '@'\nline -1 -1 -1 1 'rA':text -1 0 -1 1 'Vertical'"; @@ -775,8 +777,9 @@ void smgl_text(mglGraph *gr) // text drawing gr->SubPlot(2,2,1,""); gr->Puts(mglPoint(0,0.5), "\\sqrt{\\frac{\\alpha^{\\gamma^2}+\\overset 1{\\big\\infty}}{\\sqrt3{2+b}}}", "@", -2); - gr->Puts(mglPoint(0,-0.3),"Text can be printed\non several lines"); - gr->Puts(mglPoint(0,-0.7),"or with col\bor gradient","BbcyrR"); + gr->Puts(mglPoint(0,-0.1),"More text position: \\frac{a}{b}, \\dfrac{a}{b}, [\\stack{a}{bbb}], [\\stackl{a}{bbb}], [\\stackr{a}{bbb}], \\sup{a}{sup}, \\sub{a}{sub}"); + gr->Puts(mglPoint(0,-0.5),"Text can be printed\non several lines"); + gr->Puts(mglPoint(0,-0.9),"or with col\bor gradient","BbcyrR"); gr->SubPlot(2,2,2,""); mglData y; mgls_prepare1d(&y); @@ -1388,8 +1391,8 @@ void smgl_pde(mglGraph *gr) // PDE sample gr->Puts(mglPoint(0, 0.95), "Equation: ik_0\\partial_zu + \\Delta u + x\\cdot u + i \\frac{x+z}{2}\\cdot u = 0\nabsorption: (x+z)/2 for x+z>0"); } //----------------------------------------------------------------------------- -const char *mmgl_conta="call 'prepare3d'\ntitle 'Cont3 sample':rotate 50 60:box\ncont3 c 'x':cont3 c:cont3 c 'z'"; -void smgl_conta(mglGraph *gr) +const char *mmgl_cont3="call 'prepare3d'\ntitle 'Cont3 sample':rotate 50 60:box\ncont3 c 'x':cont3 c:cont3 c 'z'"; +void smgl_cont3(mglGraph *gr) { mglData c; mgls_prepare3d(&c); if(big!=3) gr->Title("Cont3 sample"); @@ -1397,9 +1400,9 @@ void smgl_conta(mglGraph *gr) gr->Cont3(c,"x"); gr->Cont3(c); gr->Cont3(c,"z"); } //----------------------------------------------------------------------------- -const char *mmgl_contfa="call 'prepare3d'\ntitle 'Cont3 sample':rotate 50 60:box:light on\n" +const char *mmgl_contf3="call 'prepare3d'\ntitle 'Cont3 sample':rotate 50 60:box:light on\n" "contf3 c 'x':contf3 c:contf3 c 'z'\ncont3 c 'xk':cont3 c 'k':cont3 c 'zk'"; -void smgl_contfa(mglGraph *gr) +void smgl_contf3(mglGraph *gr) { mglData c; mgls_prepare3d(&c); if(big!=3) gr->Title("ContF3 sample"); @@ -1408,9 +1411,9 @@ void smgl_contfa(mglGraph *gr) gr->Cont3(c,"kx"); gr->Cont3(c,"k"); gr->Cont3(c,"kz"); } //----------------------------------------------------------------------------- -const char *mmgl_densa="call 'prepare3d'\ntitle 'Dens3 sample':rotate 50 60:alpha on:alphadef 0.7\n" +const char *mmgl_dens3="call 'prepare3d'\ntitle 'Dens3 sample':rotate 50 60:alpha on:alphadef 0.7\n" "origin 0 0 0:box:axis '_xyz'\ndens3 c 'x':dens3 c ':y':dens3 c 'z'"; -void smgl_densa(mglGraph *gr) +void smgl_dens3(mglGraph *gr) { mglData c; mgls_prepare3d(&c); if(big!=3) gr->Title("Dens3 sample"); @@ -1470,7 +1473,7 @@ void smgl_cloud(mglGraph *gr) //----------------------------------------------------------------------------- const char *mmgl_cont="call 'prepare2d'\nlist v -0.5 -0.15 0 0.15 0.5\nsubplot 2 2 0:title 'Cont plot (default)':rotate 50 60:box:cont a\n" "subplot 2 2 1:title 'manual levels':rotate 50 60:box:cont v a\n" -"subplot 2 2 2:title '\"\\_\" style':rotate 50 60:box:cont a '_'\n" +"subplot 2 2 2:title '\"\\_\" and \".\" styles':rotate 50 60:box:cont a '_':cont a '_.2k'\n" "subplot 2 2 3 '':title '\"t\" style':box:cont a 't'"; void smgl_cont(mglGraph *gr) { @@ -1480,8 +1483,8 @@ void smgl_cont(mglGraph *gr) if(big==3) return; 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,2); gr->Title("'\\_' and '.' styles"); + gr->Rotate(50,60); gr->Box(); gr->Cont(a,"_"); gr->Cont(a,"_.2k"); gr->SubPlot(2,2,3,""); gr->Title("'t' style"); gr->Box(); gr->Cont(a,"t"); } @@ -1731,26 +1734,64 @@ void smgl_surf(mglGraph *gr) gr->Rotate(50,60); gr->Box(); gr->Surf(x,y,z,"BbwrR"); } //----------------------------------------------------------------------------- -const char *mmgl_parser="title 'MGL parser sample'\ncall 'sample'\nstop\nfunc 'sample'\n" -"new dat 100 'sin(2*pi*(x+1))'\nplot dat; xrange 0 1\nbox\naxis\n" -"xlabel 'x'\nylabel 'y'\nbox\nfor $0 -1 1 0.1\nif $0<0\n" -"line 0 0 -1 $0 'r':else:line 0 0 -1 $0 'g'\nendif\nnext"; +const char *mmgl_parser="title 'MGL parser sample'\n# call function\ncall 'sample'\n" +"\n# ordinary for-loop\nfor $0 -1 1 0.1\n" +"if $0<0:line 0 0 1 $0 'r':else:line 0 0 1 $0 'g':endif\nnext\n" +"\n# if-elseif-else\nfor $i -1 1 0.5\nif $i<0\ntext 1.1 $i '$i' 'b'\n" +"elseif $i>0\ntext 1.1 $i '$i' 'r'\nelse\ntext 1.1 $i '$i'\nendif\nnext\n" +"\n# ordinary do-while\ndo\ndefnum $i $i-0.2\nline 0 0 $i 1 'b'\nwhile $i>0\n" +"\n# do-next-break\ndo\ndefnum $i $i-0.2\nif $i<-1 then break\nline 0 0 $i 1 'm'\nnext\n" +"\n# for-while-continue\nfor $i -5 10\ntext $i/5 1.1 'a'+($i+5)\nif $i<0\n" +"text $i/5-0.06 1.1 '--' 'b'\nelseif mod($i,2)=0\ntext $i/5-0.06 1.1 '~' 'r'\n" +"else\n# NOTE: 'continue' bypass the 'while'!\ncontinue\nendif\n" +"# NOTE: 'while' limit the actual number of iterations\nwhile $i<5\n" +"\n# nested loops\nfor $i 0 1 0.1\nfor $j 0 1 0.1\nball $i $j\n" +"if $j>0.5 then continue\nball $i $j 'b+'\nnext\nnext\n" +"\nfunc 'sample'\nnew dat 100 'sin(2*pi*(i/99+1))'\nplot dat;xrange -1 0\n" +"box:axis\nxlabel 'x':ylabel 'y'\nreturn"; void smgl_parser(mglGraph *gr) // example of MGL parsing -{ +{ // NOTE: MGL version show much more variants of loops and conditions. gr->Title("MGL parser sample"); double a[100]; // let a_i = sin(4*pi*x), x=0...1 - for(int i=0;i<100;i++)a[i]=sin(4*M_PI*i/99); + for(int i=0;i<100;i++)a[i]=sin(2*M_PI*i/99); mglParse *parser = new mglParse; + // Add MGL variable and set yours data to it. mglData *d = dynamic_cast(parser->AddVar("dat")); - if(d) d->Set(a,100); // set data to variable - parser->Execute(gr, "plot dat; xrange 0 1\nbox\naxis"); - // you may break script at any line do something - // and continue after that + if(d) d->Set(a,100); + parser->Execute(gr, "plot dat; xrange -1 0\nbox\naxis"); + // You may break script at any line do something + // and continue after that. parser->Execute(gr, "xlabel 'x'\nylabel 'y'\nbox"); - // also you may use cycles or conditions in script + // Also you may use cycles or conditions in script. parser->Execute(gr, "for $0 -1 1 0.1\nif $0<0\n" - "line 0 0 -1 $0 'r':else:line 0 0 -1 $0 'g'\n" + "line 0 0 1 $0 'r':else:line 0 0 1 $0 'g'\n" "endif\nnext"); + // You may use for or do-while loops as C/C++ one + double i=1; + do { + char buf[64]; sprintf(buf,"line 0 0 %g 1 'b'",i); + parser->Execute(gr, buf); i=i-0.2; + } while(i>0); + // or as MGL one. + parser->Execute(gr, "for $i -1 1 0.5\n" + "if $i<0\ntext 1.1 $i '$i' 'b'\n" + "elseif $i>0\ntext 1.1 $i '$i' 'r'\n" + "else\ntext 1.1 $i '$i'\nendif\nnext\n"); + // There are 'break' and 'continue' commands in MGL too. + // NOTE: 'next' act as "while(1)" in do-while loops. + parser->Execute(gr, "do\ndefnum $i $i-0.2\n" + "if $i<-1 then break\nline 0 0 $i 1 'm'\nnext\n"); + // One issue with 'continue' -- it bypass 'while' checking + parser->Execute(gr, "for $i -5 10\ntext $i/5 1.1 'a'+($i+5)\nif $i<0\n" + "text $i/5-0.06 1.1 '--' 'b'\n" + "elseif mod($i,2)=0\ntext $i/5-0.06 1.1 '~' 'r'\n" + "else\ncontinue\nendif\n" + // NOTE: 'while' limit the actual number of iterations in for-loop. + "while $i<5\n"); + // Finally, MGL support nested loops too. + parser->Execute(gr, "for $i 0 1 0.1\nfor $j 0 1 0.1\nball $i $j\n" + "if $j>0.5 then continue\nball $i $j 'b+'\nnext\nnext\n"); + // Clean up memory. delete parser; } //----------------------------------------------------------------------------- @@ -1786,24 +1827,26 @@ const char *mmgl_surfc="call 'prepare2d'\ntitle 'SurfC plot':rotate 50 60:light void smgl_surfc(mglGraph *gr) { mglData a,b; mgls_prepare2d(&a,&b); - if(big!=3) gr->Title("SurfC plot"); gr->Rotate(50,60); - gr->Light(true); gr->Box(); gr->SurfC(a,b); + if(big!=3) gr->Title("SurfC plot"); + gr->Rotate(50,60); gr->Light(true); gr->Box(); gr->SurfC(a,b); } //----------------------------------------------------------------------------- const char *mmgl_surfca="call 'prepare2d'\ntitle 'SurfCA plot':rotate 50 60:light on:alpha on:box:surfca a b a"; void smgl_surfca(mglGraph *gr) { mglData a,b; mgls_prepare2d(&a,&b); - if(big!=3) gr->Title("SurfCA plot"); gr->Rotate(50,60); - gr->Alpha(true); gr->Light(true); gr->Box(); gr->SurfCA(a,b,a); + if(big!=3) gr->Title("SurfCA plot"); + gr->Rotate(50,60); gr->Alpha(true); gr->Light(true); gr->Box(); + gr->SurfCA(a,b,a); } //----------------------------------------------------------------------------- const char *mmgl_surfa="call 'prepare2d'\ntitle 'SurfA plot':rotate 50 60:light on:alpha on:box:surfa a b"; void smgl_surfa(mglGraph *gr) { mglData a,b; mgls_prepare2d(&a,&b); - if(big!=3) gr->Title("SurfA plot"); gr->Rotate(50,60); - gr->Alpha(true); gr->Light(true); gr->Box(); gr->SurfA(a,b); + if(big!=3) gr->Title("SurfA plot"); + gr->Rotate(50,60); gr->Alpha(true); gr->Light(true); gr->Box(); + gr->SurfA(a,b); } //----------------------------------------------------------------------------- const char *mmgl_tile="call 'prepare2d'\ntitle 'Tile plot':rotate 50 60:box:tile a"; @@ -1863,12 +1906,12 @@ void smgl_fit(mglGraph *gr) // nonlinear fitting // gr->SetRanges(mglPoint(-1,-1,-1),mglPoint(1,1,1)); gr->SetOrigin(0,0,0); } //----------------------------------------------------------------------------- -const char *mmgl_vecta="call 'prepare3v'\nsubplot 2 1 0:title 'Vect3 sample':rotate 50 60\n" +const char *mmgl_vect3="call 'prepare3v'\nsubplot 2 1 0:title 'Vect3 sample':rotate 50 60\n" "origin 0 0 0:box:axis '_xyz'\nvect3 ex ey ez 'x':vect3 ex ey ez:vect3 ex ey ez 'z'\n" "subplot 2 1 1:title '\"f\" style':rotate 50 60\n" "origin 0 0 0:box:axis '_xyz'\nvect3 ex ey ez 'fx':vect3 ex ey ez 'f':vect3 ex ey ez 'fz'\n" "grid3 ex 'Wx':grid3 ex 'W':grid3 ex 'Wz'"; -void smgl_vecta(mglGraph *gr) +void smgl_vect3(mglGraph *gr) { mglData ex,ey,ez; mgls_prepare3v(&ex,&ey,&ez); if(big!=3) { gr->SubPlot(2,1,0); gr->Title("Vect3 sample"); } @@ -1894,9 +1937,12 @@ void smgl_vect(mglGraph *gr) gr->Box(); gr->Vect(a,b); if(big==3) return; gr->SubPlot(3,2,1,""); gr->Title("'.' style; '=' style"); gr->Box(); gr->Vect(a,b,"=."); - gr->SubPlot(3,2,2,""); gr->Title("'f' style"); gr->Box(); gr->Vect(a,b,"f"); - gr->SubPlot(3,2,3,""); gr->Title("'>' style"); gr->Box(); gr->Vect(a,b,">"); - gr->SubPlot(3,2,4,""); gr->Title("'<' style"); gr->Box(); gr->Vect(a,b,"<"); + gr->SubPlot(3,2,2,""); gr->Title("'f' style"); + gr->Box(); gr->Vect(a,b,"f"); + gr->SubPlot(3,2,3,""); gr->Title("'>' style"); + gr->Box(); gr->Vect(a,b,">"); + gr->SubPlot(3,2,4,""); gr->Title("'<' style"); + gr->Box(); gr->Vect(a,b,"<"); mglData ex,ey,ez; mgls_prepare3v(&ex,&ey,&ez); gr->SubPlot(3,2,5); gr->Title("3d variant"); gr->Rotate(50,60); gr->Box(); gr->Vect(ex,ey,ez); @@ -1904,7 +1950,7 @@ void smgl_vect(mglGraph *gr) //----------------------------------------------------------------------------- const char *mmgl_flow="call 'prepare2v'\ncall 'prepare3v'\nsubplot 2 2 0 '':title 'Flow plot (default)':box:flow a b\n" "subplot 2 2 1 '':title '\"v\" style':box:flow a b 'v'\n" -"subplot 2 2 2 '':title 'from edges only':box:flow a b '#'\n" +"subplot 2 2 2 '':title '\"#\" and \".\" styles':box:flow a b '#':flow a b '.2k'\n" "subplot 2 2 3:title '3d variant':rotate 50 60:box:flow ex ey ez"; void smgl_flow(mglGraph *gr) { @@ -1912,13 +1958,34 @@ void smgl_flow(mglGraph *gr) if(big!=3) {gr->SubPlot(2,2,0,""); gr->Title("Flow plot (default)");} gr->Box(); gr->Flow(a,b); if(big==3) return; - gr->SubPlot(2,2,1,""); gr->Title("'v' style"); gr->Box(); gr->Flow(a,b,"v"); - gr->SubPlot(2,2,2,""); gr->Title("'\\#' style"); gr->Box(); gr->Flow(a,b,"#"); + gr->SubPlot(2,2,1,""); gr->Title("'v' style"); + gr->Box(); gr->Flow(a,b,"v"); + gr->SubPlot(2,2,2,""); gr->Title("'\\#' and '.' styles"); + gr->Box(); gr->Flow(a,b,"#"); gr->Flow(a,b,".2k"); mglData ex,ey,ez; mgls_prepare3v(&ex,&ey,&ez); gr->SubPlot(2,2,3); gr->Title("3d variant"); gr->Rotate(50,60); gr->Box(); gr->Flow(ex,ey,ez); } //----------------------------------------------------------------------------- +const char *mmgl_flow3="call 'prepare3v'\n" +"subplot 2 2 0:title 'Flow3 plot (default)':rotate 50 60:box\nflow3 ex ey ez\n" +"subplot 2 2 1:title '\"v\" style, from boundary':rotate 50 60:box\nflow3 ex ey ez 'v' 0\n" +"subplot 2 2 2:title '\"t\" style':rotate 50 60:box\nflow3 ex ey ez 't' 0\n" +"subplot 2 2 3:title 'from \\i z planes':rotate 50 60:box\nflow3 ex ey ez 'z' 0\nflow3 ex ey ez 'z' 9"; +void smgl_flow3(mglGraph *gr) +{ + mglData ex,ey,ez; mgls_prepare3v(&ex,&ey,&ez); + if(big!=3) {gr->SubPlot(2,2,0); gr->Title("Flow3 plot (default)");} + gr->Rotate(50,60); gr->Box(); gr->Flow3(ex,ey,ez); + if(big==3) return; + gr->SubPlot(2,2,1); gr->Title("'v' style, from boundary"); + gr->Rotate(50,60); gr->Box(); gr->Flow3(ex,ey,ez,"v",0); + gr->SubPlot(2,2,2); gr->Title("'t' style"); + gr->Rotate(50,60); gr->Box(); gr->Flow3(ex,ey,ez,"t",0); + gr->SubPlot(2,2,3); gr->Title("from \\i z planes"); + gr->Rotate(50,60); gr->Box(); gr->Flow3(ex,ey,ez,"z",0); gr->Flow3(ex,ey,ez,"z",9); +} +//----------------------------------------------------------------------------- const char *mmgl_pipe="call 'prepare2v'\ncall 'prepare3v'\nsubplot 2 2 0 '':title 'Pipe plot (default)':light on:box:pipe a b\n" "subplot 2 2 1 '':title '\"i\" style':box:pipe a b 'i'\n" "subplot 2 2 2 '':title 'from edges only':box:pipe a b '#'\n" @@ -2091,7 +2158,7 @@ void smgl_axis(mglGraph *gr) gr->InPlot(0,0.5,0,0.5); gr->SetRanges(1,0,4,0); gr->FPlot("4*x^2"); } //----------------------------------------------------------------------------- -const char *mmgl_ticks="subplot 3 3 0:title 'Usual axis'\naxis\n\n" +const char *mmgl_ticks="subplot 3 3 0:title 'Usual axis with \":\" style'\naxis ':'\n\n" "subplot 3 3 1:title 'Too big/small range'\nranges -1000 1000 0 0.001:axis\n\n" "subplot 3 3 2:title 'LaTeX-like labels'\naxis 'F!'\n\n" "subplot 3 3 3:title 'Too narrow range'\nranges 100 100.1 10 10.01:axis\n\n" @@ -2103,12 +2170,12 @@ const char *mmgl_ticks="subplot 3 3 0:title 'Usual axis'\naxis\n\n" "subplot 3 3 7:title 'Manual ticks'\nranges -pi pi 0 2\n" "xtick pi 3 '\\pi'\nxtick 0.886 'x^*' on # note this will disable subticks drawing\n" "# or you can use\n#xtick -pi '\\pi' -pi/2 '-\\pi/2' 0 '0' 0.886 'x^*' pi/2 '\\pi/2' pi 'pi'\n" -"# or you can use\n#list v -pi -pi/2 0 0.886 pi/2 pi:xtick v '-\\pi\\n-\\pi/2\\n{}0\\n{}x^*\\n\\pi/2\\n\\pi'\n" +"list v 0 0.5 1 2:ytick v '0\n0.5\n1\n2'\n" "axis:grid:fplot '2*cos(x^2)^2' 'r2'\n\n" "subplot 3 3 8:title 'Time ticks'\nxrange 0 3e5:ticktime 'x':axis"; void smgl_ticks(mglGraph *gr) { - gr->SubPlot(3,3,0); gr->Title("Usual axis"); gr->Axis(); + gr->SubPlot(3,3,0); gr->Title("Usual axis with ':' style"); gr->Axis(":"); gr->SubPlot(3,3,1); gr->Title("Too big/small range"); gr->SetRanges(-1000,1000,0,0.001); gr->Axis(); gr->SubPlot(3,3,2); gr->Title("LaTeX-like labels"); @@ -2128,8 +2195,8 @@ void smgl_ticks(mglGraph *gr) gr->SubPlot(3,3,7); gr->Title("Manual ticks"); gr->SetRanges(-M_PI,M_PI, 0, 2); gr->SetTicks('x',M_PI,0,0,"\\pi"); gr->AddTick('x',0.886,"x^*"); // alternatively you can use following lines - //double val[]={-M_PI, -M_PI/2, 0, 0.886, M_PI/2, M_PI}; - //gr->SetTicksVal('x', mglData(6,val), "-\\pi\n-\\pi/2\n0\nx^*\n\\pi/2\n\\pi"); + double val[]={0, 0.5, 1, 2}; + gr->SetTicksVal('y', mglData(4,val), "0\n0.5\n1\n2"); gr->Axis(); gr->Grid(); gr->FPlot("2*cos(x^2)^2", "r2"); gr->SubPlot(3,3,8); gr->Title("Time ticks"); gr->SetRange('x',0,3e5); gr->SetTicksTime('x',0); gr->Axis(); @@ -2206,13 +2273,17 @@ const char *mmgl_primitives="subplot 2 2 0 '':title 'Line, Curve, Rhomb, Ellipse "line -1 -1 -0.5 1 'qAI'\ncurve -0.6 -1 1 1 0 1 1 1 'rA'\nball 0 -0.5 '*':ball 1 -0.1 '*'\n" "rhomb 0 0.4 1 0.9 0.2 'b#'\nrhomb 0 0 1 0.4 0.2 'cg@'\n" "ellipse 0 -0.5 1 -0.1 0.2 'u#'\nellipse 0 -1 1 -0.6 0.2 'm@'\n\n" -"light on\nsubplot 2 2 1:title 'Face[xyz]':rotate 50 60:box\n" +"subplot 2 3 1 '':title 'Arc, Polygon, Symbol';size -1.2\n" +"arc -0.6 0 -0.6 0.3 180 '2kA':ball -0.6 0\npolygon 0 0 0 0.4 6 'r'\n" +"new x 50 'cos(3*pi*x)':new y 50 'sin(pi*x)'\n" +"addsymbol 'a' x y\nsymbol 0.7 0 'a'\n\n" +"light on\nsubplot 2 3 3 '<^>' 0 -0.2:title 'Face[xyz]';size -1.5:rotate 50 60:box\n" "facex 1 0 -1 1 1 'r':facey -1 -1 -1 1 1 'g':facez 1 -1 -1 -1 1 'b'\n" "face -1 -1 1 -1 1 1 1 -1 0 1 1 1 'bmgr'\n\n" -"subplot 2 2 3 '':title 'Cone'\n" -"cone -0.7 -0.3 0 -0.7 0.7 0.5 0.2 0.1 'b':text -0.7 -0.7 'no edges\\n(default)'\n" -"cone 0 -0.3 0 0 0.7 0.5 0.2 0.1 'g@':text 0 -0.7 'with edges\\n('\\@' style)'\n" -"cone 0.7 -0.3 0 0.7 0.7 0.5 0.2 0.1 'ry':text 0.7 -0.7 '\"arrow\" with\\n{}gradient'\n\n" +"subplot 2 3 5 '':title 'Cone';size -1.5\n" +"cone -0.7 -0.3 0 -0.7 0.7 0.5 0.2 0.1 'b':text -0.7 -0.7 'no edges\\n(default)';size -1.5\n" +"cone 0 -0.3 0 0 0.7 0.5 0.2 0.1 'g@':text 0 -0.7 'with edges\\n(\"\\@\" style)';size -1.5\n" +"cone 0.7 -0.3 0 0.7 0.7 0.5 0.2 0 'Ggb':text 0.7 -0.7 '\"arrow\" with\\n{}gradient';size -1.5\n" "subplot 2 2 2 '':title 'Sphere and Drop'\nline -0.9 0 1 0.9 0 1\n" "text -0.9 0.4 'sh=0':drop -0.9 0 0 1 0.5 'r' 0:ball -0.9 0 1 'k'\n" "text -0.3 0.6 'sh=0.33':drop -0.3 0 0 1 0.5 'r' 0.33:ball -0.3 0 1 'k'\n" @@ -2233,20 +2304,27 @@ void smgl_primitives(mglGraph *gr) // flag # gr->Ellipse(mglPoint(0,-1),mglPoint(1,-0.6),0.2,"m@"); gr->Mark(mglPoint(0,-0.5),"*"); gr->Mark(mglPoint(1,-0.1),"*"); + gr->SubPlot(2,3,1,""); gr->Title("Arc, Polygon, Symbol","", -1.2*2); + gr->Arc(mglPoint(-0.6,0), mglPoint(-0.6,0.3), 180, "2kA"); gr->Ball(-0.6,0); + gr->Polygon(mglPoint(), mglPoint(0,0.4), 6, "r"); + mglData x(50), y(50); gr->Fill(x,"cos(3*pi*x)"); gr->Fill(y,"sin(pi*x)"); + gr->DefineSymbol('a',x,y); gr->Symbol(mglPoint(0.7),'a'); + gr->Light(true); - gr->SubPlot(2,2,1); gr->Title("Face[xyz]"); gr->Rotate(50,60); gr->Box(); + gr->SubPlot(2,3,3,"<^>",0,-0.2); gr->Title("Face[xyz]", "", -1.5*2); + gr->Rotate(50,60); gr->Box(); gr->FaceX(mglPoint(1,0,-1),1,1,"r"); gr->FaceY(mglPoint(-1,-1,-1),1,1,"g"); gr->FaceZ(mglPoint(1,-1,-1),-1,1,"b"); gr->Face(mglPoint(-1,-1,1),mglPoint(-1,1,1),mglPoint(1,-1,0),mglPoint(1,1,1),"bmgr"); - gr->SubPlot(2,2,3,""); gr->Title("Cone"); + gr->SubPlot(2,3,5,""); gr->Title("Cone", "", -1.5*2); gr->Cone(mglPoint(-0.7,-0.3),mglPoint(-0.7,0.7,0.5),0.2,0.1,"b"); - gr->Puts(mglPoint(-0.7,-0.7),"no edges\n(default)"); + gr->Puts(mglPoint(-0.7,-0.7),"no edges\n(default)","", -1.5); gr->Cone(mglPoint(0,-0.3),mglPoint(0,0.7,0.5),0.2,0.1,"g@"); - gr->Puts(mglPoint(0,-0.7),"with edges\n('\\@' style)"); + gr->Puts(mglPoint(0,-0.7),"with edges\n('\\@' style)","", -1.5); gr->Cone(mglPoint(0.7,-0.3),mglPoint(0.7,0.7,0.5),0.2,0,"ry"); - gr->Puts(mglPoint(0.7,-0.7),"'arrow' with\ngradient"); + gr->Puts(mglPoint(0.7,-0.7),"'arrow' with\ngradient","", -1.5); gr->SubPlot(2,2,2,""); gr->Title("Sphere and Drop"); gr->Alpha(false); gr->Puts(mglPoint(-0.9,0.4),"sh=0"); gr->Ball(mglPoint(-0.9,0,1),'k'); @@ -2334,10 +2412,11 @@ void smgl_colorbar(mglGraph *gr) const char *mmgl_legend="addlegend 'sin(\\pi {x^2})' 'b':addlegend 'sin(\\pi x)' 'g*'\n" "addlegend 'sin(\\pi \\sqrt{x})' 'rd':addlegend 'jsut text' ' ':addlegend 'no indent for this' ''\n" "subplot 2 2 0 '':title 'Legend (default)':box:legend\n" +"legend 1 0.5 '^':text 0.49 0.88 'Style \"\\^\"' 'A:L'\n" "legend 3 'A#':text 0.75 0.65 'Absolute position' 'A'\n" "subplot 2 2 2 '':title 'coloring':box:legend 0 'r#':legend 1 'Wb#':legend 2 'ygr#'\n" "subplot 2 2 3 '':title 'manual position':box\n" -"legend 0.5 1:text 0.5 0.55 'at x=0.5, y=1' 'a'\n" +"legend 0.5 1:text 0.5 0.5 'at x=0.5, y=1' 'a'\n" "legend 1 '#-':text 0.75 0.25 'Horizontal legend' 'a'"; void smgl_legend(mglGraph *gr) { @@ -2349,13 +2428,14 @@ void smgl_legend(mglGraph *gr) if(big!=3) {gr->SubPlot(2,2,0,""); gr->Title("Legend (default)");} gr->Box(); gr->Legend(); if(big==3) return; + gr->Legend(1,0.5,"^"); gr->Puts(0.49, 0.88, "Style '\\^'","A:L"); 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,1); - gr->Puts(mglPoint(0.5,0.55),"at x=0.5, y=1","a"); + gr->Puts(mglPoint(0.5,0.5),"at x=0.5, y=1","a"); gr->Legend(1,"#-"); gr->Puts(mglPoint(0.75,0.25),"Horizontal legend","a"); } @@ -2782,129 +2862,703 @@ void smgl_ifs3d(mglGraph *gr) gr->Dots(f.SubData(0), f.SubData(1), f.SubData(2),"G#o","size 0.05"); } //----------------------------------------------------------------------------- +const char *mmgl_flame2d="list A [0.33,0,0,0.33,0,0,0.2] [0.33,0,0,0.33,0.67,0,0.2] [0.33,0,0,0.33,0.33,0.33,0.2]\\\n" +"\t[0.33,0,0,0.33,0,0.67,0.2] [0.33,0,0,0.33,0.67,0.67,0.2]\n" +"new B 2 3 A.ny '0.3'\nput B 3 0 0 -1\nput B 3 0 1 -1\nput B 3 0 2 -1\n" +"flame2d fx fy A B 1000000\nsubplot 1 1 0 '<_':title 'Flame2d sample'\n" +"ranges fx fy:box:axis\nplot fx fy 'r#o ';size 0.05"; +void smgl_flame2d(mglGraph *gr) +{ + mglData A, B(2,3,5); + A.SetList(35, 0.33,0.,0.,0.33,0.,0.,0.2, 0.33,0.,0.,0.33,0.67,0.,0.2, 0.33,0.,0.,0.33,0.33,0.33,0.2, + 0.33,0.,0.,0.33,0.,0.67,0.2, 0.33,0.,0.,0.33,0.67,0.67,0.2); + A.Rearrange(7); + for(long i=0;i<2*3*5;i++) B.a[i] = 0.3; + for(long i=0;i<5;i++) B.a[2*3*i] = B.a[2*3*i+1*2] = B.a[2*3*i+2*2] = 3; + mglData f(mglFlame2d(A,B,1000000)); + gr->SubPlot(1,1,0,"<_"); + if(big!=3) gr->Title("Flame2d sample"); + gr->SetRanges(f.SubData(0), f.SubData(1)); + gr->Axis(); gr->Box(); + gr->Plot(f.SubData(0), f.SubData(1),"r#o ","size 0.05"); +} +//----------------------------------------------------------------------------- +const char *mmgl_detect="subplot 1 1 0 '':title 'Detect sample'\n" +"new a 200 100 'exp(-30*(y-0.5*sin(pi*x))^2-rnd/10)+exp(-30*(y+0.5*sin(pi*x))^2-rnd/10)+exp(-30*(x+y)^2-rnd/10)'\n" +"ranges 0 a.nx 0 a.ny:box\nalpha on:crange a:dens a\n\n" +"detect r a 0.1 5\nplot r(0) r(1) '.'"; +void smgl_detect(mglGraph *gr) +{ + mglData a(200, 100); + gr->Fill(a,"exp(-30*(y-0.5*sin(pi*x))^2-rnd/10)+exp(-30*(y+0.5*sin(pi*x))^2-rnd/10)+exp(-30*(x+y)^2-rnd/10)"); + gr->SubPlot(1,1,0,""); + if(big!=3) gr->Title("Detect sample"); + gr->SetRanges(0,a.nx,0,a.ny); gr->SetRange('c',a); + gr->Alpha(true); gr->Box(); gr->Dens(a); + mglData r(a.Detect(0.1,5)); + gr->Plot(r.SubData(0), r.SubData(1), "."); +} +//----------------------------------------------------------------------------- +const char *mmgl_iris="read a 'iris.dat'\ncrop a 0 4 'x':rearrange a a.nx 50\n" +"subplot 1 1 0 '':title 'Iris plot'\n" +"iris a 'sepal\\n length;sepal\\n width;petal\\n length;petal\\n width' '. ';value -1.5;size -2"; +void smgl_iris(mglGraph *gr) +{ + mglData a("iris.dat"); a.Crop(0,4,'x'); a.Rearrange(4,50); + gr->SubPlot(1,1,0,""); + if(big!=3) gr->Title("Iris sample"); + gr->Iris(a, "sepal\nlength;sepal\nwidth;petal\nlength;petal\nwidth", ". ", "value -1.5;size -2"); +} +//----------------------------------------------------------------------------- +const char *mmgl_dilate="subplot 2 2 0:title 'Dilate&Erode 1D sample'\n" +"new y 11:put y 1 5\nranges 0 10 0 1:axis:box\nplot y 'b*'\n" +"dilate y 0.5 2\nplot y 'rs'\nerode y 0.5 1\nplot y 'g#o'\n\n" +"subplot 2 2 1:title 'Dilate&Erode 2D sample':rotate 40 60\n" +"ranges 0 10 0 10 0 3\naxis:box\nnew z 11 11:put z 3 5 5\n" +"boxs z 'b':boxs z 'k#'\ndilate z 1 2\nboxs z 'r':boxs z 'k#'\n" +"erode z 1 1\nboxs 2*z 'g':boxs 2*z 'k#'\n\n" +"subplot 2 2 2\ntext 0.5 0.7 'initial' 'ba';size -2\n" +"text 0.5 0.5 'dilate=2' 'ra';size -2\ntext 0.5 0.3 'erode=1' 'ga';size -2\n\n" +"subplot 2 2 3:title 'Dilate&Erode 3D sample'\nrotate 60 50:light on:alpha on\n" +"ranges 0 10 0 10 0 10:crange 0 3\naxis:box\nnew a 11 11 11:put a 3 5 5 5\n" +"surf3a a a 1.5 'b'\ndilate a 1 2\nsurf3a a a 0.5 'r'\n" +"erode a 1 1\nsurf3a 2*a 2*a 1 'g'"; +void smgl_dilate(mglGraph *gr) +{ + mglData y(11), z(11,11), a(11,11,11); + y.a[5]=1; z.a[5+11*5]=a.a[5+11*(5+11*5)] = 3; + + if(big!=3) { gr->SubPlot(2,2,0); gr->Title("Dilate&Erode 1D sample"); } + else gr->SubPlot(1,1,0,""); + gr->SetRanges(0,10,0,1); gr->Axis(); gr->Box(); gr->Plot(y,"b*"); + y.Dilate(1,2); gr->Plot(y,"rs"); + y.Erode(1,1); gr->Plot(y,"g#o"); + if(big==3) return; + + gr->SubPlot(2,2,1); gr->Title("Dilate&Erode 2D sample"); + gr->Rotate(40,60); gr->SetRanges(0,10,0,10,0,3); + gr->Axis(); gr->Box(); gr->Boxs(z,"b"); gr->Boxs(z,"k#"); + z.Dilate(1,2); gr->Boxs(z,"r"); gr->Boxs(z,"k#"); + z.Erode(1,1); z*=2; gr->Boxs(z,"g"); gr->Boxs(z,"k#"); + + gr->SubPlot(2,2,2); + gr->Puts(0.5,0.7,"initial","ba",-2); + gr->Puts(0.5,0.5,"dilate=2","ra",-2); + gr->Puts(0.5,0.3,"erode=1","ga",-2); + + gr->SubPlot(2,2,3); gr->Title("Dilate&Erode 3D sample"); + gr->Rotate(60,50); gr->Alpha(true); gr->Light(true); + gr->SetRanges(0,10,0,10,0,10); gr->SetRange('c',0,3); + gr->Axis(); gr->Box(); gr->Surf3A(1.5,a,a,"b"); + a.Dilate(1,2); gr->Surf3A(0.5,a,a,"r"); + a.Erode(1,1); a*=2; gr->Surf3A(1,a,a,"g"); +} +//----------------------------------------------------------------------------- +const char *mmgl_section="subplot 1 1 0 '<_':title 'Section&Join sample'\n" +"axis:box:line -1 0 1 0 'h:'\n# first lets demonstrate 'join'\n" +"new aa 11 'x^2':new a1 3 '-x':new a2 15 'x^3'\njoin aa a1:join aa a2\n" +"# add x-coordinate\nnew xx aa.nx 'x':join aa xx\nplot aa(:,1) aa(:,0) '2y'\n" +"# now select 1-st (id=0) section between zeros\n" +"section b1 aa 0 'x' 0\nplot b1(:,1) b1(:,0) 'bo'\n" +"# next, select 3-d (id=2) section between zeros\n" +"section b3 aa 2 'x' 0\nplot b3(:,1) b3(:,0) 'gs'\n" +"# finally, select 2-nd (id=-2) section from the end\n" +"section b4 aa -2 'x' 0\nplot b4(:,1) b4(:,0) 'r#o'"; +void smgl_section(mglGraph *gr) +{ + gr->SubPlot(1,1,0,"<_"); + if(big!=3) gr->Title("Section&Join sample"); + gr->Axis(); gr->Box(); gr->Line(mglPoint(-1,0),mglPoint(1,0),"h:"); + // first lets demonstrate 'join' + mglData aa(11), a1(3), a2(15); + gr->Fill(aa,"x^2"); gr->Fill(a1,"-x"); gr->Fill(a2,"x^3"); + aa.Join(a1); aa.Join(a2); + // add x-coordinate + mglData xx(aa.nx); gr->Fill(xx,"x"); aa.Join(xx); + gr->Plot(aa.SubData(-1,1), aa.SubData(-1,0), "2y"); + // now select 1-st (id=0) section between zeros + mglData b1(aa.Section(0,'x',0)); + gr->Plot(b1.SubData(-1,1), b1.SubData(-1,0), "bo"); + // next, select 3-d (id=2) section between zeros + mglData b2(aa.Section(2,'x',0)); + gr->Plot(b2.SubData(-1,1), b2.SubData(-1,0), "gs"); + // finally, select 2-nd (id=-2) section from the end + mglData b3(aa.Section(-2,'x',0)); + gr->Plot(b3.SubData(-1,1), b3.SubData(-1,0), "r#o"); +} +//----------------------------------------------------------------------------- +const char *mmgl_3wave="define t 50\n" +"ode !r '-b*f;a*conj(f);a*conj(b)-0.1*f' 'abf' [1,1e-3,0] 0.1 t\n" +"ranges 0 t 0 r.max\nplot r(0) 'b';legend 'a'\n" +"plot r(1) 'g';legend 'b'\nplot r(2) 'r';legend 'f'\n" +"axis:box:legend"; +void smgl_3wave(mglGraph *gr) +{ + gr->SubPlot(1,1,0,"<_"); + if(big!=3) gr->Title("Complex ODE sample"); + double t=50; + mglData ini; ini.SetList(3, 1., 1e-3, 0.); + mglDataC r(mglODEc("-b*f;a*conj(f);a*conj(b)-0.1*f","abf",ini,0.1,t)); + gr->SetRanges(0, t, 0, r.Maximal()); + gr->Plot(r.SubData(0),"b","legend 'a'"); + gr->Plot(r.SubData(1),"g","legend 'b'"); + gr->Plot(r.SubData(2),"r","legend 'f'"); + gr->Axis(); gr->Box(); gr->Legend(); +} +//----------------------------------------------------------------------------- +const char *mmgl_diffract="define n 32 #number of points\ndefine m 20 # number of iterations\n" +"define dt 0.01 # time step\nnew res n m+1\nranges -1 1 0 m*dt 0 1\n\n" +"#tridmat periodic variant\nnew !a n 'i',dt*(n/2)^2/2\ncopy !b !(1-2*a)\n\n" +"new !u n 'exp(-6*x^2)'\nput res u all 0\nfor $i 0 m\ntridmat u a b a u 'xdc'\n" +"put res u all $i+1\nnext\nsubplot 2 2 0 '<_':title 'Tridmat, periodic b.c.'\naxis:box:dens res\n\n" +"#fourier variant\nnew k n:fillsample k 'xk'\ncopy !e !exp(-i1*dt*k^2)\n\n" +"new !u n 'exp(-6*x^2)'\nput res u all 0\nfor $i 0 m\nfourier u 'x'\nmulto u e\nfourier u 'ix'\n" +"put res u all $i+1\nnext\nsubplot 2 2 1 '<_':title 'Fourier method'\naxis:box:dens res\n\n" +"#tridmat zero variant\nnew !u n 'exp(-6*x^2)'\nput res u all 0\nfor $i 0 m\ntridmat u a b a u 'xd'\n" +"put res u all $i+1\nnext\nsubplot 2 2 2 '<_':title 'Tridmat, zero b.c.'\naxis:box:dens res\n\n" +"#diffract exp variant\nnew !u n 'exp(-6*x^2)'\ndefine q dt*(n/2)^2/8 # need q<0.4 !!!\n" +"put res u all 0\nfor $i 0 m\nfor $j 1 8 # due to smaller dt\ndiffract u 'xe' q\nnext\n" +"put res u all $i+1\nnext\nsubplot 2 2 3 '<_':title 'Diffract, exp b.c.'\naxis:box:dens res"; +void smgl_diffract(mglGraph *gr) +{ + long n=32; // number of points + long m=20; // number of iterations + double dt=0.01; // time step + mglData res(n,m+1); + gr->SetRanges(-1,1, 0,m*dt, 0,1); + + // tridmat periodic variant + mglDataC a(n), b(n); a = dual(0,dt*n*n/8); + for(long i=0;iFill(u,"exp(-6*x^2)"); res.Put(u,-1,0); + for(long i=0;iSubPlot(2,2,0,"<_"); gr->Title("Tridmat, periodic b.c."); + gr->Axis(); gr->Box(); gr->Dens(res); + + // fourier variant + mglData k(n); k.FillSample("xk"); + mglDataC e(n); for(long i=0;iFill(u,"exp(-6*x^2)"); res.Put(u,-1,0); + for(long i=0;iSubPlot(2,2,1,"<_"); gr->Title("Fourier method"); + gr->Axis(); gr->Box(); gr->Dens(res); + + // tridmat zero variant + gr->Fill(u,"exp(-6*x^2)"); res.Put(u,-1,0); + for(long i=0;iSubPlot(2,2,2,"<_"); gr->Title("Tridmat, zero b.c."); + gr->Axis(); gr->Box(); gr->Dens(res); + + // diffract exp variant + gr->Fill(u,"exp(-6*x^2)"); res.Put(u,-1,0); + double q=dt*n*n/4/8; // NOTE: need q<0.4 !!! + for(long i=0;iSubPlot(2,2,3,"<_"); gr->Title("Diffract, exp b.c."); + gr->Axis(); gr->Box(); gr->Dens(res); +} +//----------------------------------------------------------------------------- +const char *mmgl_earth="import dat 'Equirectangular-projection.jpg' 'BbGYw' -1 1\n" +"subplot 1 1 0 '<>':title 'Earth in 3D':rotate 40 60\n" +"copy phi dat 'pi*x':copy tet dat 'pi*y/2'\n" +"copy x cos(tet)*cos(phi)\ncopy y cos(tet)*sin(phi)\ncopy z sin(tet)\n\n" +"light on\nsurfc x y z dat 'BbGYw'\ncontp [-0.51,-0.51] x y z dat 'y'"; +void smgl_earth(mglGraph *gr) +{ + mglData dat; dat.Import("Equirectangular-projection.jpg","BbGYw",-1,1); + // Calc proper 3d coordinates from projection + mglData phi(dat.nx,dat.ny); phi.Fill(-M_PI,M_PI); + mglData tet(dat.nx,dat.ny); tet.Fill(-M_PI/2,M_PI/2,'y'); + mglData x(dat.nx,dat.ny), y(dat.nx,dat.ny), z(dat.nx,dat.ny); +#pragma omp parallel for + for(long i=0;iSubPlot(1,1,0,"<>"); + if(big!=3) gr->Title("Earth in 3D"); + gr->Rotate(40,60); gr->Light(true); + gr->SurfC(x,y,z,dat,"BbGYw"); + mglData vals(1); vals.a[0]=-0.51; + gr->ContP(vals, x,y,z,dat,"y"); +} +//----------------------------------------------------------------------------- +#define all_prims_str "subplot 3 2 0:define y 0.95\n\ +define d 0.3:define x0 0.2:define x1 0.5:define x2 0.6\n\ +line x0 1-0*d x1 1-0*d 'k-':text x2 y-0*d 'Solid `-`' ':rL'\n\ +line x0 1-1*d x1 1-1*d 'k|':text x2 y-1*d 'Long Dash `|`' ':rL'\n\ +line x0 1-2*d x1 1-2*d 'k;':text x2 y-2*d 'Dash 1;`' ':rL'\n\ +line x0 1-3*d x1 1-3*d 'k=':text x2 y-3*d 'Small dash `=`' ':rL'\n\ +line x0 1-4*d x1 1-4*d 'kj':text x2 y-4*d 'Dash-dot `j`' ':rL'\n\ +line x0 1-5*d x1 1-5*d 'ki':text x2 y-5*d 'Small dash-dot `i`' ':rL'\n\ +line x0 1-6*d x1 1-6*d 'k:':text x2 y-6*d 'Dots `:`' ':rL'\n\ +line x0 1-7*d x1 1-7*d 'k ':text x2 y-7*d 'None ``' ':rL'\n\ +define d 0.25:define x0 -0.8:define x1 -1:define x2 -0.05\n\ +ball x1 5*d 'k.':text x0 5*d '.' ':rL'\n\ +ball x1 4*d 'k+':text x0 4*d '+' ':rL'\n\ +ball x1 3*d 'kx':text x0 3*d 'x' ':rL'\n\ +ball x1 2*d 'k*':text x0 2*d '*' ':rL'\n\ +ball x1 d 'ks':text x0 d 's' ':rL'\n\ +ball x1 0 'kd':text x0 0 'd' ':rL'\n\ +ball x1 -d 0 'ko':text x0 y-d 'o' ':rL'\n\ +ball x1 -2*d 0 'k^':text x0 -2*d '\\^' ':rL'\n\ +ball x1 -3*d 0 'kv':text x0 -3*d 'v' ':rL'\n\ +ball x1 -4*d 0 'k<':text x0 -4*d '<' ':rL'\n\ +ball x1 -5*d 0 'k>':text x0 -5*d '>' ':rL'\n\n\ +define x0 -0.3:define x1 -0.5\n\ +ball x1 5*d 'k#.':text x0 5*d '\\#.' ':rL'\n\ +ball x1 4*d 'k#+':text x0 4*d '\\#+' ':rL'\n\ +ball x1 3*d 'k#x':text x0 3*d '\\#x' ':rL'\n\ +ball x1 2*d 'k#*':text x0 2*d '\\#*' ':rL'\n\ +ball x1 d 'k#s':text x0 d '\\#s' ':rL'\n\ +ball x1 0 'k#d':text x0 0 '\\#d' ':rL'\n\ +ball x1 -d 0 'k#o':text x0 -d '\\#o' ':rL'\n\ +ball x1 -2*d 0 'k#^':text x0 -2*d '\\#\\^' ':rL'\n\ +ball x1 -3*d 0 'k#v':text x0 -3*d '\\#v' ':rL'\n\ +ball x1 -4*d 0 'k#<':text x0 -4*d '\\#<' ':rL'\n\ +ball x1 -5*d 0 'k#>':text x0 -5*d '\\#>' ':rL'\n\n\ +subplot 3 2 1\ndefine a 0.1:define b 0.4:define c 0.5\n\ +line a 1 b 1 'k-A':text c 1 'Style `A` or `A\\_`' ':rL'\n\ +line a 0.8 b 0.8 'k-V':text c 0.8 'Style `V` or `V\\_`' ':rL'\n\ +line a 0.6 b 0.6 'k-K':text c 0.6 'Style `K` or `K\\_`' ':rL'\n\ +line a 0.4 b 0.4 'k-I':text c 0.4 'Style `I` or `I\\_`' ':rL'\n\ +line a 0.2 b 0.2 'k-D':text c 0.2 'Style `D` or `D\\_`' ':rL'\n\ +line a 0 b 0 'k-S':text c 0 'Style `S` or `S\\_`' ':rL'\n\ +line a -0.2 b -0.2 'k-O':text c -0.2 'Style `O` or `O\\_`' ':rL'\n\ +line a -0.4 b -0.4 'k-T':text c -0.4 'Style `T` or `T\\_`' ':rL'\n\ +line a -0.6 b -0.6 'k-_':text c -0.6 'Style `\\_` or none' ':rL'\n\ +line a -0.8 b -0.8 'k-AS':text c -0.8 'Style `AS`' ':rL'\n\ +line a -1 b -1 'k-_A':text c -1 'Style `\\_A`' ':rL'\n\n\ +define a -1:define b -0.7:define c -0.6\n\ +line a 1 b 1 'kAA':text c 1 'Style `AA`' ':rL'\n\ +line a 0.8 b 0.8 'kVV':text c 0.8 'Style `VV`' ':rL'\n\ +line a 0.6 b 0.6 'kKK':text c 0.6 'Style `KK`' ':rL'\n\ +line a 0.4 b 0.4 'kII':text c 0.4 'Style `II`' ':rL'\n\ +line a 0.2 b 0.2 'kDD':text c 0.2 'Style `DD`' ':rL'\n\ +line a 0 b 0 'kSS':text c 0 'Style `SS`' ':rL'\n\ +line a -0.2 b -0.2 'kOO':text c -0.2 'Style `OO`' ':rL'\n\ +line a -0.4 b -0.4 'kTT':text c -0.4 'Style `TT`' ':rL'\n\ +line a -0.6 b -0.6 'k-__':text c -0.6 'Style `\\_\\_`' ':rL'\n\ +line a -0.8 b -0.8 'k-VA':text c -0.8 'Style `VA`' ':rL'\n\ +line a -1 b -1 'k-AV':text c -1 'Style `AV`' ':rL'\n\n\ +subplot 3 2 2\n#LENUQ\n\n\ +facez -1 -1 0 0.4 0.3 'L#':text -0.8 -0.9 'L' 'w:C' -1.4\n\ +facez -0.6 -1 0 0.4 0.3 'E#':text -0.4 -0.9 'E' 'w:C' -1.4\n\ +facez -0.2 -1 0 0.4 0.3 'N#':text 0 -0.9 'N' 'w:C' -1.4\n\ +facez 0.2 -1 0 0.4 0.3 'U#':text 0.4 -0.9 'U' 'w:C' -1.4\n\ +facez 0.6 -1 0 0.4 0.3 'Q#':text 0.8 -0.9 'Q' 'w:C' -1.4\n\ +#lenuq\nfacez -1 -0.7 0 0.4 0.3 'l#':text -0.8 -0.6 'l' 'k:C' -1.4\n\ +facez -0.6 -0.7 0 0.4 0.3 'e#':text -0.4 -0.6 'e' 'k:C' -1.4\n\ +facez -0.2 -0.7 0 0.4 0.3 'n#':text 0 -0.6 'n' 'k:C' -1.4\n\ +facez 0.2 -0.7 0 0.4 0.3 'u#':text 0.4 -0.6 'u' 'k:C' -1.4\n\ +facez 0.6 -0.7 0 0.4 0.3 'q#':text 0.8 -0.6 'q' 'k:C' -1.4\n\ +#CMYkP\nfacez -1 -0.4 0 0.4 0.3 'C#':text -0.8 -0.3 'C' 'w:C' -1.4\n\ +facez -0.6 -0.4 0 0.4 0.3 'M#':text -0.4 -0.3 'M' 'w:C' -1.4\n\ +facez -0.2 -0.4 0 0.4 0.3 'Y#':text 0 -0.3 'Y' 'w:C' -1.4\n\ +facez 0.2 -0.4 0 0.4 0.3 'k#':text 0.4 -0.3 'k' 'w:C' -1.4\n\ +facez 0.6 -0.4 0 0.4 0.3 'P#':text 0.8 -0.3 'P' 'w:C' -1.4\n\ +#cmywp\nfacez -1 -0.1 0 0.4 0.3 'c#':text -0.8 0 'c' 'k:C' -1.4\n\ +facez -0.6 -0.1 0 0.4 0.3 'm#':text -0.4 0 'm' 'k:C' -1.4\n\ +facez -0.2 -0.1 0 0.4 0.3 'y#':text 0 0 'y' 'k:C' -1.4\n\ +facez 0.2 -0.1 0 0.4 0.3 'w#':text 0.4 0 'w' 'k:C' -1.4\n\ +facez 0.6 -0.1 0 0.4 0.3 'p#':text 0.8 0 'p' 'k:C' -1.4\n\ +#BGRHW\nfacez -1 0.2 0 0.4 0.3 'B#':text -0.8 0.3 'B' 'w:C' -1.4\n\ +facez -0.6 0.2 0 0.4 0.3 'G#':text -0.4 0.3 'G' 'w:C' -1.4\n\ +facez -0.2 0.2 0 0.4 0.3 'R#':text 0 0.3 'R' 'w:C' -1.4\n\ +facez 0.2 0.2 0 0.4 0.3 'H#':text 0.4 0.3 'H' 'w:C' -1.4\n\ +facez 0.6 0.2 0 0.4 0.3 'W#':text 0.8 0.3 'W' 'w:C' -1.4\n\ +#bgrhw\nfacez -1 0.5 0 0.4 0.3 'b#':text -0.8 0.6 'b' 'k:C' -1.4\n\ +facez -0.6 0.5 0 0.4 0.3 'g#':text -0.4 0.6 'g' 'k:C' -1.4\n\ +facez -0.2 0.5 0 0.4 0.3 'r#':text 0 0.6 'r' 'k:C' -1.4\n\ +facez 0.2 0.5 0 0.4 0.3 'h#':text 0.4 0.6 'h' 'k:C' -1.4\n\ +facez 0.6 0.5 0 0.4 0.3 'w#':text 0.8 0.6 'w' 'k:C' -1.4\n\ +#brighted\nfacez -1 0.8 0 0.4 0.3 '{r1}#':text -0.8 0.9 '\\{r1\\}' 'w:C' -1.4\n\ +facez -0.6 0.8 0 0.4 0.3 '{r3}#':text -0.4 0.9 '\\{r3\\}' 'w:C' -1.4\n\ +facez -0.2 0.8 0 0.4 0.3 '{r5}#':text 0 0.9 '\\{r5\\}' 'k:C' -1.4\n\ +facez 0.2 0.8 0 0.4 0.3 '{r7}#':text 0.4 0.9 '\\{r7\\}' 'k:C' -1.4\n\ +facez 0.6 0.8 0 0.4 0.3 '{r9}#':text 0.8 0.9 '\\{r9\\}' 'k:C' -1.4\n\ +# HEX\nfacez -1 -1.3 0 1 0.3 '{xff9966}#':text -0.5 -1.2 '\\{xff9966\\}' 'k:C' -1.4\n\ +facez 0 -1.3 0 1 0.3 '{x83CAFF}#':text 0.5 -1.2 '\\{x83caff\\}' 'k:C' -1.4\n\n\ +subplot 3 2 3\nfor $i 0 9\nline -1 0.2*$i-1 1 0.2*$i-1 'r','0'+$i\n\ +text 1.05 0.2*$i-1 '0'+$i ':L'\nnext\n\n\ +subplot 3 2 4:title 'TriPlot sample':rotate 50 60\n\ +list tt 0 1 2 | 0 1 3 | 0 2 3 | 1 2 3\n\ +list xt -1 1 0 0:list yt -1 -1 1 0:list zt -1 -1 -1 1:light on\n\ +triplot tt xt yt zt 'b':triplot tt xt yt zt 'k#'\n\n\ +subplot 3 2 5:new r 4 'i+1':ranges 1 4 1 4\naxis:mark r r 's':plot r 'b'\n" +void all_prims(mglGraph *gr) // test drawing of all kinds +{ + gr->SubPlot(3,2,0); + double d,x1,x2,x0,y=0.95; + d=0.3, x0=0.2, x1=0.5, x2=0.6; + gr->Line(mglPoint(x0,1-0*d),mglPoint(x1,1-0*d),"k-"); gr->Puts(mglPoint(x2,y-0*d),"Solid '-'",":rL"); + gr->Line(mglPoint(x0,1-1*d),mglPoint(x1,1-1*d),"k|"); gr->Puts(mglPoint(x2,y-1*d),"Long Dash '|'",":rL"); + gr->Line(mglPoint(x0,1-2*d),mglPoint(x1,1-2*d),"k;"); gr->Puts(mglPoint(x2,y-2*d),"Dash ';'",":rL"); + gr->Line(mglPoint(x0,1-3*d),mglPoint(x1,1-3*d),"k="); gr->Puts(mglPoint(x2,y-3*d),"Small dash '='",":rL"); + gr->Line(mglPoint(x0,1-4*d),mglPoint(x1,1-4*d),"kj"); gr->Puts(mglPoint(x2,y-4*d),"Dash-dot 'j'",":rL"); + gr->Line(mglPoint(x0,1-5*d),mglPoint(x1,1-5*d),"ki"); gr->Puts(mglPoint(x2,y-5*d),"Small dash-dot 'i'",":rL"); + gr->Line(mglPoint(x0,1-6*d),mglPoint(x1,1-6*d),"k:"); gr->Puts(mglPoint(x2,y-6*d),"Dots ':'",":rL"); + gr->Line(mglPoint(x0,1-7*d),mglPoint(x1,1-7*d),"k "); gr->Puts(mglPoint(x2,y-7*d),"None ' '",":rL"); + + d=0.25; x1=-1; x0=-0.8; y = -0.05; + gr->Mark(mglPoint(x1,5*d),"k."); gr->Puts(mglPoint(x0,y+5*d),"'.'",":rL"); + gr->Mark(mglPoint(x1,4*d),"k+"); gr->Puts(mglPoint(x0,y+4*d),"'+'",":rL"); + gr->Mark(mglPoint(x1,3*d),"kx"); gr->Puts(mglPoint(x0,y+3*d),"'x'",":rL"); + gr->Mark(mglPoint(x1,2*d),"k*"); gr->Puts(mglPoint(x0,y+2*d),"'*'",":rL"); + gr->Mark(mglPoint(x1,d),"ks"); gr->Puts(mglPoint(x0,y+d),"'s'",":rL"); + gr->Mark(mglPoint(x1,0),"kd"); gr->Puts(mglPoint(x0,y),"'d'",":rL"); + gr->Mark(mglPoint(x1,-d,0),"ko"); gr->Puts(mglPoint(x0,y-d),"'o'",":rL"); + gr->Mark(mglPoint(x1,-2*d,0),"k^"); gr->Puts(mglPoint(x0,y-2*d),"'\\^'",":rL"); + gr->Mark(mglPoint(x1,-3*d,0),"kv"); gr->Puts(mglPoint(x0,y-3*d),"'v'",":rL"); + gr->Mark(mglPoint(x1,-4*d,0),"k<"); gr->Puts(mglPoint(x0,y-4*d),"'<'",":rL"); + gr->Mark(mglPoint(x1,-5*d,0),"k>"); gr->Puts(mglPoint(x0,y-5*d),"'>'",":rL"); + + d=0.25; x1=-0.5; x0=-0.3; y = -0.05; + gr->Mark(mglPoint(x1,5*d),"k#."); gr->Puts(mglPoint(x0,y+5*d),"'\\#.'",":rL"); + gr->Mark(mglPoint(x1,4*d),"k#+"); gr->Puts(mglPoint(x0,y+4*d),"'\\#+'",":rL"); + gr->Mark(mglPoint(x1,3*d),"k#x"); gr->Puts(mglPoint(x0,y+3*d),"'\\#x'",":rL"); + gr->Mark(mglPoint(x1,2*d),"k#*"); gr->Puts(mglPoint(x0,y+2*d),"'\\#*'",":rL"); + gr->Mark(mglPoint(x1,d),"k#s"); gr->Puts(mglPoint(x0,y+d),"'\\#s'",":rL"); + gr->Mark(mglPoint(x1,0),"k#d"); gr->Puts(mglPoint(x0,y),"'\\#d'",":rL"); + gr->Mark(mglPoint(x1,-d,0),"k#o"); gr->Puts(mglPoint(x0,y-d),"'\\#o'",":rL"); + gr->Mark(mglPoint(x1,-2*d,0),"k#^"); gr->Puts(mglPoint(x0,y-2*d),"'\\#\\^'",":rL"); + gr->Mark(mglPoint(x1,-3*d,0),"k#v"); gr->Puts(mglPoint(x0,y-3*d),"'\\#v'",":rL"); + gr->Mark(mglPoint(x1,-4*d,0),"k#<"); gr->Puts(mglPoint(x0,y-4*d),"'\\#<'",":rL"); + gr->Mark(mglPoint(x1,-5*d,0),"k#>"); gr->Puts(mglPoint(x0,y-5*d),"'\\#>'",":rL"); + + gr->SubPlot(3,2,1); + double a=0.1,b=0.4,c=0.5; + gr->Line(mglPoint(a,1),mglPoint(b,1),"k-A"); gr->Puts(mglPoint(c,1),"Style 'A' or 'A\\_'",":rL"); + gr->Line(mglPoint(a,0.8),mglPoint(b,0.8),"k-V"); gr->Puts(mglPoint(c,0.8),"Style 'V' or 'V\\_'",":rL"); + gr->Line(mglPoint(a,0.6),mglPoint(b,0.6),"k-K"); gr->Puts(mglPoint(c,0.6),"Style 'K' or 'K\\_'",":rL"); + gr->Line(mglPoint(a,0.4),mglPoint(b,0.4),"k-I"); gr->Puts(mglPoint(c,0.4),"Style 'I' or 'I\\_'",":rL"); + gr->Line(mglPoint(a,0.2),mglPoint(b,0.2),"k-D"); gr->Puts(mglPoint(c,0.2),"Style 'D' or 'D\\_'",":rL"); + gr->Line(mglPoint(a,0),mglPoint(b,0),"k-S"); gr->Puts(mglPoint(c,0),"Style 'S' or 'S\\_'",":rL"); + gr->Line(mglPoint(a,-0.2),mglPoint(b,-0.2),"k-O"); gr->Puts(mglPoint(c,-0.2),"Style 'O' or 'O\\_'",":rL"); + gr->Line(mglPoint(a,-0.4),mglPoint(b,-0.4),"k-T"); gr->Puts(mglPoint(c,-0.4),"Style 'T' or 'T\\_'",":rL"); + gr->Line(mglPoint(a,-0.6),mglPoint(b,-0.6),"k-_"); gr->Puts(mglPoint(c,-0.6),"Style '\\_' or none",":rL"); + gr->Line(mglPoint(a,-0.8),mglPoint(b,-0.8),"k-AS"); gr->Puts(mglPoint(c,-0.8),"Style 'AS'",":rL"); + gr->Line(mglPoint(a,-1),mglPoint(b,-1),"k-_A"); gr->Puts(mglPoint(c,-1),"Style '\\_A'",":rL"); + + a=-1; b=-0.7; c=-0.6; + gr->Line(mglPoint(a,1),mglPoint(b,1),"kAA"); gr->Puts(mglPoint(c,1),"Style 'AA'",":rL"); + gr->Line(mglPoint(a,0.8),mglPoint(b,0.8),"kVV"); gr->Puts(mglPoint(c,0.8),"Style 'VV'",":rL"); + gr->Line(mglPoint(a,0.6),mglPoint(b,0.6),"kKK"); gr->Puts(mglPoint(c,0.6),"Style 'KK'",":rL"); + gr->Line(mglPoint(a,0.4),mglPoint(b,0.4),"kII"); gr->Puts(mglPoint(c,0.4),"Style 'II'",":rL"); + gr->Line(mglPoint(a,0.2),mglPoint(b,0.2),"kDD"); gr->Puts(mglPoint(c,0.2),"Style 'DD'",":rL"); + gr->Line(mglPoint(a,0),mglPoint(b,0),"kSS"); gr->Puts(mglPoint(c,0),"Style 'SS'",":rL"); + gr->Line(mglPoint(a,-0.2),mglPoint(b,-0.2),"kOO"); gr->Puts(mglPoint(c,-0.2),"Style 'OO'",":rL"); + gr->Line(mglPoint(a,-0.4),mglPoint(b,-0.4),"kTT"); gr->Puts(mglPoint(c,-0.4),"Style 'TT'",":rL"); + gr->Line(mglPoint(a,-0.6),mglPoint(b,-0.6),"k-__"); gr->Puts(mglPoint(c,-0.6),"Style '\\_\\_'",":rL"); + gr->Line(mglPoint(a,-0.8),mglPoint(b,-0.8),"k-VA"); gr->Puts(mglPoint(c,-0.8),"Style 'VA'",":rL"); + gr->Line(mglPoint(a,-1),mglPoint(b,-1),"k-AV"); gr->Puts(mglPoint(c,-1),"Style 'AV'",":rL"); + + gr->SubPlot(3,2,2); + //#LENUQ + gr->FaceZ(mglPoint(-1, -1), 0.4, 0.3, "L#"); gr->Puts(mglPoint(-0.8,-0.9), "L", "w:C", -1.4); + gr->FaceZ(mglPoint(-0.6,-1), 0.4, 0.3, "E#"); gr->Puts(mglPoint(-0.4,-0.9), "E", "w:C", -1.4); + gr->FaceZ(mglPoint(-0.2,-1), 0.4, 0.3, "N#"); gr->Puts(mglPoint(0, -0.9), "N", "w:C", -1.4); + gr->FaceZ(mglPoint(0.2, -1), 0.4, 0.3, "U#"); gr->Puts(mglPoint(0.4,-0.9), "U", "w:C", -1.4); + gr->FaceZ(mglPoint(0.6, -1), 0.4, 0.3, "Q#"); gr->Puts(mglPoint(0.8,-0.9), "Q", "w:C", -1.4); + //#lenuq + gr->FaceZ(mglPoint(-1, -0.7), 0.4, 0.3, "l#"); gr->Puts(mglPoint(-0.8,-0.6), "l", "k:C", -1.4); + gr->FaceZ(mglPoint(-0.6,-0.7), 0.4, 0.3, "e#"); gr->Puts(mglPoint(-0.4,-0.6), "e", "k:C", -1.4); + gr->FaceZ(mglPoint(-0.2,-0.7), 0.4, 0.3, "n#"); gr->Puts(mglPoint(0, -0.6), "n", "k:C", -1.4); + gr->FaceZ(mglPoint(0.2, -0.7), 0.4, 0.3, "u#"); gr->Puts(mglPoint(0.4,-0.6), "u", "k:C", -1.4); + gr->FaceZ(mglPoint(0.6, -0.7), 0.4, 0.3, "q#"); gr->Puts(mglPoint(0.8,-0.6), "q", "k:C", -1.4); + //#CMYkP + gr->FaceZ(mglPoint(-1, -0.4), 0.4, 0.3, "C#"); gr->Puts(mglPoint(-0.8,-0.3), "C", "w:C", -1.4); + gr->FaceZ(mglPoint(-0.6,-0.4), 0.4, 0.3, "M#"); gr->Puts(mglPoint(-0.4,-0.3), "M", "w:C", -1.4); + gr->FaceZ(mglPoint(-0.2,-0.4), 0.4, 0.3, "Y#"); gr->Puts(mglPoint(0, -0.3), "Y", "w:C", -1.4); + gr->FaceZ(mglPoint(0.2, -0.4), 0.4, 0.3, "k#"); gr->Puts(mglPoint(0.4,-0.3), "k", "w:C", -1.4); + gr->FaceZ(mglPoint(0.6, -0.4), 0.4, 0.3, "P#"); gr->Puts(mglPoint(0.8,-0.3), "P", "w:C", -1.4); + //#cmywp + gr->FaceZ(mglPoint(-1, -0.1), 0.4, 0.3, "c#"); gr->Puts(mglPoint(-0.8, 0), "c", "k:C", -1.4); + gr->FaceZ(mglPoint(-0.6,-0.1), 0.4, 0.3, "m#"); gr->Puts(mglPoint(-0.4, 0), "m", "k:C", -1.4); + gr->FaceZ(mglPoint(-0.2,-0.1), 0.4, 0.3, "y#"); gr->Puts(mglPoint(0, 0), "y", "k:C", -1.4); + gr->FaceZ(mglPoint(0.2, -0.1), 0.4, 0.3, "w#"); gr->Puts(mglPoint(0.4, 0), "w", "k:C", -1.4); + gr->FaceZ(mglPoint(0.6, -0.1), 0.4, 0.3, "p#"); gr->Puts(mglPoint(0.8, 0), "p", "k:C", -1.4); + //#BGRHW + gr->FaceZ(mglPoint(-1, 0.2), 0.4, 0.3, "B#"); gr->Puts(mglPoint(-0.8, 0.3), "B", "w:C", -1.4); + gr->FaceZ(mglPoint(-0.6,0.2), 0.4, 0.3, "G#"); gr->Puts(mglPoint(-0.4, 0.3), "G", "w:C", -1.4); + gr->FaceZ(mglPoint(-0.2,0.2), 0.4, 0.3, "R#"); gr->Puts(mglPoint(0, 0.3), "R", "w:C", -1.4); + gr->FaceZ(mglPoint(0.2, 0.2), 0.4, 0.3, "H#"); gr->Puts(mglPoint(0.4, 0.3), "H", "w:C", -1.4); + gr->FaceZ(mglPoint(0.6, 0.2), 0.4, 0.3, "W#"); gr->Puts(mglPoint(0.8, 0.3), "W", "w:C", -1.4); + //#bgrhw + gr->FaceZ(mglPoint(-1, 0.5), 0.4, 0.3, "b#"); gr->Puts(mglPoint(-0.8, 0.6), "b", "k:C", -1.4); + gr->FaceZ(mglPoint(-0.6,0.5), 0.4, 0.3, "g#"); gr->Puts(mglPoint(-0.4, 0.6), "g", "k:C", -1.4); + gr->FaceZ(mglPoint(-0.2,0.5), 0.4, 0.3, "r#"); gr->Puts(mglPoint(0, 0.6), "r", "k:C", -1.4); + gr->FaceZ(mglPoint(0.2, 0.5), 0.4, 0.3, "h#"); gr->Puts(mglPoint(0.4, 0.6), "h", "k:C", -1.4); + gr->FaceZ(mglPoint(0.6, 0.5), 0.4, 0.3, "w#"); gr->Puts(mglPoint(0.8, 0.6), "w", "k:C", -1.4); + //#brighted + gr->FaceZ(mglPoint(-1, 0.8), 0.4, 0.3, "{r1}#"); gr->Puts(mglPoint(-0.8, 0.9), "\\{r1\\}", "w:C", -1.4); + gr->FaceZ(mglPoint(-0.6,0.8), 0.4, 0.3, "{r3}#"); gr->Puts(mglPoint(-0.4, 0.9), "\\{r3\\}", "w:C", -1.4); + gr->FaceZ(mglPoint(-0.2,0.8), 0.4, 0.3, "{r5}#"); gr->Puts(mglPoint(0, 0.9), "\\{r5\\}", "k:C", -1.4); + gr->FaceZ(mglPoint(0.2, 0.8), 0.4, 0.3, "{r7}#"); gr->Puts(mglPoint(0.4, 0.9), "\\{r7\\}", "k:C", -1.4); + gr->FaceZ(mglPoint(0.6, 0.8), 0.4, 0.3, "{r9}#"); gr->Puts(mglPoint(0.8, 0.9), "\\{r9\\}", "k:C", -1.4); + // HEX + gr->FaceZ(mglPoint(-1, -1.3), 1, 0.3, "{xff9966}#"); gr->Puts(mglPoint(-0.5,-1.2), "\\{xff9966\\}", "k:C", -1.4); + gr->FaceZ(mglPoint(0, -1.3), 1, 0.3, "{x83CAFF}#"); gr->Puts(mglPoint( 0.5,-1.2), "\\{x83CAFF\\}", "k:C", -1.4); + + gr->SubPlot(3,2,3); + char stl[3]="r1", txt[4]="'1'"; + for(int i=0;i<10;i++) + { + txt[1]=stl[1]='0'+i; + gr->Line(mglPoint(-1,0.2*i-1),mglPoint(1,0.2*i-1),stl); + gr->Puts(mglPoint(1.05,0.2*i-1),txt,":L"); + } + + gr->SubPlot(3,2,4); gr->Title("TriPlot sample"); gr->Rotate(50,60); + double t[] = {0,1,2, 0,1,3, 0,2,3, 1,2,3}; + double 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->TriPlot(tt,uu,vv,ww,"b"); + gr->TriPlot(tt,uu,vv,ww,"k#"); + + gr->SubPlot(3,2,5); + mglData r(4); r.Fill(1,4); + gr->SetRanges(1,4,1,4); gr->Axis(); + gr->Mark(r,r,"s"); + gr->Plot(r,"b"); +} +//----------------------------------------------------------------------------- +const char *mmgl_fexport=all_prims_str +"write 'fexport.jpg':#write 'fexport.png'\nwrite 'fexport.bmp':write 'fexport.tga'\n" +"write 'fexport.eps':write 'fexport.svg'\nwrite 'fexport.gif':write 'fexport.xyz'\n" +"write 'fexport.stl':write 'fexport.off'\nwrite 'fexport.tex':write 'fexport.obj'\n" +"write 'fexport.prc':write 'fexport.json'\nwrite 'fexport.mgld'"; +void smgl_fexport(mglGraph *gr) // test file export +{ + all_prims(gr); + gr->WriteJPEG("fexport.jpg"); +// gr->WritePNG("fexport.png"); + gr->WriteBMP("fexport.bmp"); + gr->WriteTGA("fexport.tga"); + gr->WriteEPS("fexport.eps"); + gr->WriteSVG("fexport.svg"); + gr->WriteGIF("fexport.gif"); + + gr->WriteXYZ("fexport.xyz"); + gr->WriteSTL("fexport.stl"); + gr->WriteOFF("fexport.off"); + gr->WriteTEX("fexport.tex"); + gr->WriteOBJ("fexport.obj"); + gr->WritePRC("fexport.prc"); + gr->WriteJSON("fexport.json"); + + gr->ExportMGLD("fexport.mgld"); + gr->Clf(); + gr->ImportMGLD("fexport.mgld"); +} +//----------------------------------------------------------------------------- +const char *mmgl_quality0="quality 0\n" +all_prims_str; +void smgl_quality0(mglGraph *gr) // test file export +{ + gr->SetQuality(0); all_prims(gr); +} +//----------------------------------------------------------------------------- +const char *mmgl_quality1="quality 1\n" +all_prims_str; +void smgl_quality1(mglGraph *gr) // test file export +{ + gr->SetQuality(1); all_prims(gr); +} +//----------------------------------------------------------------------------- +const char *mmgl_quality2="quality 2\n" +all_prims_str; +void smgl_quality2(mglGraph *gr) // test file export +{ + gr->SetQuality(2); all_prims(gr); +} +//----------------------------------------------------------------------------- +const char *mmgl_quality4="quality 4\n" +all_prims_str; +void smgl_quality4(mglGraph *gr) // test file export +{ + gr->SetQuality(4); all_prims(gr); +} +//----------------------------------------------------------------------------- +const char *mmgl_quality5="quality 5\n" +all_prims_str; +void smgl_quality5(mglGraph *gr) // test file export +{ + gr->SetQuality(5); all_prims(gr); +} +//----------------------------------------------------------------------------- +const char *mmgl_quality6="quality 6\n" +all_prims_str; +void smgl_quality6(mglGraph *gr) // test file export +{ + gr->SetQuality(6); all_prims(gr); +} +//----------------------------------------------------------------------------- +const char *mmgl_quality8="quality 8\n" +all_prims_str; +void smgl_quality8(mglGraph *gr) // test file export +{ + gr->SetQuality(8); all_prims(gr); +} +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- mglSample samp[] = { - {"alpha", smgl_alpha, mmgl_alpha}, - {"apde", smgl_apde, mmgl_apde}, - {"area", smgl_area, mmgl_area}, - {"aspect", smgl_aspect, mmgl_aspect}, - {"axial", smgl_axial, mmgl_axial}, - {"axis", smgl_axis, mmgl_axis}, - {"barh", smgl_barh, mmgl_barh}, - {"bars", smgl_bars, mmgl_bars}, - {"belt", smgl_belt, mmgl_belt}, - {"bifurcation", smgl_bifurcation, mmgl_bifurcation}, - {"box", smgl_box, mmgl_box}, - {"boxplot", smgl_boxplot, mmgl_boxplot}, - {"boxs", smgl_boxs, mmgl_boxs}, - {"candle", smgl_candle, mmgl_candle}, - {"chart", smgl_chart, mmgl_chart}, - {"cloud", smgl_cloud, mmgl_cloud }, - {"colorbar", smgl_colorbar, mmgl_colorbar}, - {"combined", smgl_combined, mmgl_combined }, - {"cones", smgl_cones, mmgl_cones}, - {"cont", smgl_cont, mmgl_cont}, - {"cont_xyz", smgl_cont_xyz, mmgl_cont_xyz}, - {"conta", smgl_conta, mmgl_conta}, - {"contd", smgl_contd, mmgl_contd}, - {"contf", smgl_contf, mmgl_contf}, - {"contf_xyz", smgl_contf_xyz, mmgl_contf_xyz}, - {"contfa", smgl_contfa, mmgl_contfa}, - {"contv", smgl_contv, mmgl_contv}, - {"correl", smgl_correl, mmgl_correl}, -// {"crust", smgl_crust, mmgl_crust}, // TODO: open after triangulation - {"curvcoor", smgl_curvcoor, mmgl_curvcoor}, - {"cut", smgl_cut, mmgl_cut}, - {"dat_diff", smgl_dat_diff, mmgl_dat_diff}, - {"dat_extra", smgl_dat_extra, mmgl_dat_extra }, - {"data1", smgl_data1, mmgl_data1}, - {"data2", smgl_data2, mmgl_data2}, - {"dens", smgl_dens, mmgl_dens}, - {"dens_xyz", smgl_dens_xyz, mmgl_dens_xyz}, - {"densa", smgl_densa, mmgl_densa}, - {"dew", smgl_dew, mmgl_dew}, - {"dots", smgl_dots, mmgl_dots}, - {"error", smgl_error, mmgl_error}, - {"error2", smgl_error2, mmgl_error2}, - {"export", smgl_export, mmgl_export}, - {"fall", smgl_fall, mmgl_fall}, - {"fit", smgl_fit, mmgl_fit}, - {"flow", smgl_flow, mmgl_flow}, - {"fog", smgl_fog, mmgl_fog}, - {"fonts", smgl_fonts, mmgl_fonts}, - {"grad", smgl_grad, mmgl_grad}, - {"hist", smgl_hist, mmgl_hist}, - {"ifs2d", smgl_ifs2d, mmgl_ifs2d}, - {"ifs3d", smgl_ifs3d, mmgl_ifs3d}, - {"indirect",smgl_indirect,mmgl_indirect}, - {"inplot", smgl_inplot, mmgl_inplot}, - {"label", smgl_label, mmgl_label}, - {"lamerey", smgl_lamerey, mmgl_lamerey}, - {"legend", smgl_legend, mmgl_legend }, - {"light", smgl_light, mmgl_light}, - {"loglog", smgl_loglog, mmgl_loglog}, - {"map", smgl_map, mmgl_map}, - {"mark", smgl_mark, mmgl_mark}, - {"mask", smgl_mask, mmgl_mask}, - {"mesh", smgl_mesh, mmgl_mesh}, - {"mirror", smgl_mirror, mmgl_mirror }, - {"molecule", smgl_molecule, mmgl_molecule }, - {"ode", smgl_ode, mmgl_ode}, - {"ohlc", smgl_ohlc, mmgl_ohlc}, - {"param1", smgl_param1, mmgl_param1}, - {"param2", smgl_param2, mmgl_param2}, - {"param3", smgl_param3, mmgl_param3}, - {"paramv", smgl_paramv, mmgl_paramv}, - {"parser", smgl_parser, mmgl_parser}, - {"pde", smgl_pde, mmgl_pde}, - {"pendelta", smgl_pendelta, mmgl_pendelta}, - {"pipe", smgl_pipe, mmgl_pipe}, - {"plot", smgl_plot, mmgl_plot}, - {"pmap", smgl_pmap, mmgl_pmap}, - {"primitives", smgl_primitives, mmgl_primitives }, - {"projection", smgl_projection, mmgl_projection }, - {"projection5", smgl_projection5, mmgl_projection5 }, - {"pulse", smgl_pulse, mmgl_pulse }, - {"qo2d", smgl_qo2d, mmgl_qo2d}, - {"radar", smgl_radar, mmgl_radar}, - {"refill", smgl_refill, mmgl_refill}, - {"region", smgl_region, mmgl_region}, - {"scanfile", smgl_scanfile, mmgl_scanfile }, - {"schemes", smgl_schemes, mmgl_schemes }, - {"several_light", smgl_several_light, mmgl_several_light }, - {"solve", smgl_solve, mmgl_solve}, - {"stem", smgl_stem, mmgl_stem}, - {"step", smgl_step, mmgl_step}, - {"stereo", smgl_stereo, mmgl_stereo}, - {"stfa", smgl_stfa, mmgl_stfa}, - {"style", smgl_style, mmgl_style }, - {"surf", smgl_surf, mmgl_surf}, - {"surf3", smgl_surf3, mmgl_surf3}, - {"surf3a", smgl_surf3a, mmgl_surf3a}, - {"surf3c", smgl_surf3c, mmgl_surf3c}, - {"surf3ca", smgl_surf3ca, mmgl_surf3ca}, - {"surfa", smgl_surfa, mmgl_surfa}, - {"surfc", smgl_surfc, mmgl_surfc}, - {"surfca", smgl_surfca, mmgl_surfca}, - {"table", smgl_table, mmgl_table}, - {"tape", smgl_tape, mmgl_tape}, - {"tens", smgl_tens, mmgl_tens}, - {"ternary", smgl_ternary, mmgl_ternary }, - {"text", smgl_text, mmgl_text}, - {"text2", smgl_text2, mmgl_text2}, - {"textmark", smgl_textmark, mmgl_textmark}, - {"ticks", smgl_ticks, mmgl_ticks}, - {"tile", smgl_tile, mmgl_tile}, - {"tiles", smgl_tiles, mmgl_tiles}, - {"torus", smgl_torus, mmgl_torus }, - {"traj", smgl_traj, mmgl_traj}, - {"triangulation",smgl_triangulation, mmgl_triangulation }, - {"triplot", smgl_triplot, mmgl_triplot}, - {"tube", smgl_tube, mmgl_tube}, - {"type0", smgl_type0, mmgl_type0}, - {"type1", smgl_type1, mmgl_type1}, - {"type2", smgl_type2, mmgl_type2}, - {"vect", smgl_vect, mmgl_vect}, - {"vecta", smgl_vecta, mmgl_vecta}, - {"venn", smgl_venn, mmgl_venn}, -{"", NULL, NULL}}; + {"3wave", smgl_3wave, mmgl_3wave, "Example of complex @ref{ode} on basis of 3-wave decay."}, + {"alpha", smgl_alpha, mmgl_alpha, "Example of @ref{light} and @ref{alpha} (transparency)."}, + {"apde", smgl_apde, mmgl_apde, "Comparison of advanced PDE solver (@ref{apde}) and ordinary one (@ref{pde})."}, + {"area", smgl_area, mmgl_area, "Function @ref{area} fill the area between curve and axis plane. It support gradient filling if 2 colors per curve is specified."}, + {"aspect", smgl_aspect, mmgl_aspect, "Example of @ref{subplot}, @ref{inplot}, @ref{rotate}, @ref{aspect}, @ref{shear}."}, + {"axial", smgl_axial, mmgl_axial, "Function @ref{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)."}, + {"axis", smgl_axis, mmgl_axis, "Different forms of @ref{axis} position."}, + {"barh", smgl_barh, mmgl_barh, "Function @ref{barh} is the similar to @ref{bars} but draw horizontal bars."}, + {"bars", smgl_bars, mmgl_bars, "Function @ref{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."}, + {"belt", smgl_belt, mmgl_belt, "Function @ref{belt} draw surface by belts. You can use @samp{x} style for drawing lines in other direction."}, + {"bifurcation", smgl_bifurcation, mmgl_bifurcation, "Function @ref{bifurcation} draw Bifurcation diagram for multiple stationary points of the map (like logistic map)."}, + {"box", smgl_box, mmgl_box, "Different styles of bounding @ref{box}."}, + {"boxplot", smgl_boxplot, mmgl_boxplot, "Function @ref{boxplot} draw box-and-whisker diagram."}, + {"boxs", smgl_boxs, mmgl_boxs, "Function @ref{boxs} draw surface by boxes. You can use @samp{#} for drawing wire plot."}, + {"candle", smgl_candle, mmgl_candle, "Function @ref{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."}, + {"chart", smgl_chart, mmgl_chart, "Function @ref{chart} draw colored boxes with width proportional to data values. Use @samp{ } for empty box. It produce well known pie chart if drawn in polar coordinates."}, + {"cloud", smgl_cloud, mmgl_cloud , "Function @ref{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;value 10}) isosurfaces @ref{surf3a}."}, + {"colorbar", smgl_colorbar, mmgl_colorbar, "Example of @ref{colorbar} position and styles."}, + {"combined", smgl_combined, mmgl_combined , "Example of several plots in the same axis."}, + {"cones", smgl_cones, mmgl_cones, "Function @ref{cones} is similar to @ref{bars} but draw cones."}, + {"cont", smgl_cont, mmgl_cont, "Function @ref{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})."}, + {"cont3", smgl_cont3, mmgl_cont3, "Function @ref{contf3} draw ordinary contour lines but at slices of 3D data. "}, + {"cont_xyz", smgl_cont_xyz, mmgl_cont_xyz, "Functions @ref{contz}, @ref{conty}, @ref{contx} draw contour lines on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field."}, + {"contd", smgl_contd, mmgl_contd, "Function @ref{contd} is similar to @ref{contf} but with manual contour colors."}, + {"contf", smgl_contf, mmgl_contf, "Function @ref{contf} draw filled contours. You can select automatic (default) or manual levels for contours."}, + {"contf3", smgl_contf3, mmgl_contf3, "Function @ref{contf3} draw ordinary filled contours but at slices of 3D data. "}, + {"contf_xyz", smgl_contf_xyz, mmgl_contf_xyz, "Functions @ref{contfz}, @ref{contfy}, @ref{contfx}, draw filled contours on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field."}, + {"contv", smgl_contv, mmgl_contv, "Function @ref{contv} draw vertical cylinders (belts) at contour lines."}, + {"correl", smgl_correl, mmgl_correl, "Test of correlation function (@ref{correl})."}, +// {"crust", smgl_crust, mmgl_crust, ""}, // TODO: open after triangulation + {"curvcoor", smgl_curvcoor, mmgl_curvcoor, "Some common curvilinear coordinates."}, + {"cut", smgl_cut, mmgl_cut, "Example of point cutting (@ref{cut}."}, + {"dat_diff", smgl_dat_diff, mmgl_dat_diff, "Example of @ref{diff} and @ref{integrate}."}, + {"dat_extra", smgl_dat_extra, mmgl_dat_extra , "Example of @ref{envelop}, @ref{sew}, @ref{smooth} and @ref{resize}."}, + {"data1", smgl_data1, mmgl_data1, ""}, + {"data2", smgl_data2, mmgl_data2, ""}, + {"dens", smgl_dens, mmgl_dens, "Function @ref{dens} draw density plot (also known as color-map) for surface."}, + {"dens3", smgl_dens3, mmgl_dens3, "Function @ref{dens3} draw ordinary density plots but at slices of 3D data."}, + {"dens_xyz", smgl_dens_xyz, mmgl_dens_xyz, "Functions @ref{densz}, @ref{densy}, @ref{densx} draw density plot on plane perpendicular to corresponding axis. One of possible application is drawing projections of 3D field."}, + {"detect", smgl_detect, mmgl_detect, "Example of curve @ref{detect}."}, + {"dew", smgl_dew, mmgl_dew, "Function @ref{dew} is similar to @ref{vect} but use drops instead of arrows."}, + {"diffract", smgl_diffract, mmgl_diffract, ""}, + {"dilate", smgl_dilate, mmgl_dilate, "Example of @ref{dilate} and @ref{erode}."}, + {"dots", smgl_dots, mmgl_dots, "Function @ref{dots} is another way to draw irregular points. @code{Dots} use color scheme for coloring (see @ref{Color scheme})."}, + {"earth", smgl_earth, mmgl_earth, "Example of Earth map by using @ref{import}."}, + {"error", smgl_error, mmgl_error, "Function @ref{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. See also @ref{error2 sample}."}, + {"error2", smgl_error2, mmgl_error2, "Example of @ref{error} kinds."}, + {"export", smgl_export, mmgl_export, "Example of data @ref{export} and @ref{import}."}, + {"fall", smgl_fall, mmgl_fall, "Function @ref{fall} draw waterfall surface. You can use @ref{meshnum} for changing number of lines to be drawn. Also you can use @samp{x} style for drawing lines in other direction."}, + {"fexport", smgl_fexport, mmgl_fexport, "Example of @ref{write} to different file formats."}, + {"fit", smgl_fit, mmgl_fit, "Example of nonlinear @ref{fit}."}, + {"flame2d", smgl_flame2d, mmgl_flame2d, "Function @ref{flame2d} generate points for flame fractals in 2d case."}, + {"flow", smgl_flow, mmgl_flow, "Function @ref{flow} is another standard way to visualize vector fields -- it draw lines (threads) which is tangent to local vector field direction. MathGL draw threads from edges of bounding box and from central slices. Sometimes it is not most appropriate variant -- you may want to use @code{flowp} to specify manual position of threads. The color scheme is used for coloring (see @ref{Color scheme}). At this warm color corresponds to normal flow (like attractor), cold one corresponds to inverse flow (like source)."}, // TODO @ref{flowp} + {"flow3", smgl_flow3, mmgl_flow3, "Function @ref{flow3} draw flow threads, which start from given plane."}, + {"fog", smgl_fog, mmgl_fog, "Example of @ref{fog}."}, + {"fonts", smgl_fonts, mmgl_fonts, "Example of @ref{font} typefaces."}, + {"grad", smgl_grad, mmgl_grad, "Function @ref{grad} draw gradient lines for matrix."}, + {"hist", smgl_hist, mmgl_hist, "Example of @ref{hist} (histogram)."}, + {"ifs2d", smgl_ifs2d, mmgl_ifs2d, "Function @ref{ifs2d} generate points for fractals using iterated function system in 2d case."}, + {"ifs3d", smgl_ifs3d, mmgl_ifs3d, "Function @ref{ifs3d} generate points for fractals using iterated function system in 3d case."}, + {"indirect",smgl_indirect,mmgl_indirect, "Comparison of @ref{subdata} vs @ref{evaluate}/"}, + {"inplot", smgl_inplot, mmgl_inplot, "Example of @ref{inplot}, @ref{multiplot}, @ref{columnplot}, @ref{gridplot}, @ref{shearplot}, @ref{stickplot}."}, + {"iris", smgl_iris, mmgl_iris, "Function @ref{iris} draw Iris plot for columns of data array."}, + {"label", smgl_label, mmgl_label, "Function @ref{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."}, + {"lamerey", smgl_lamerey, mmgl_lamerey, "Function @ref{lamerey} draw Lamerey diagram."}, + {"legend", smgl_legend, mmgl_legend , "Example of @ref{legend} styles."}, + {"light", smgl_light, mmgl_light, "Example of @ref{light} with different types."}, + {"loglog", smgl_loglog, mmgl_loglog, "Example of log- and log-log- axis labels."}, + {"map", smgl_map, mmgl_map, "Example of @ref{map}."}, + {"mark", smgl_mark, mmgl_mark, "Example of @ref{mark}."}, + {"mask", smgl_mask, mmgl_mask, "Example of @ref{mask} kinds."}, + {"mesh", smgl_mesh, mmgl_mesh, "Function @ref{mesh} draw wired surface. You can use @ref{meshnum} for changing number of lines to be drawn."}, + {"mirror", smgl_mirror, mmgl_mirror , "Example of using options."}, + {"molecule", smgl_molecule, mmgl_molecule , "Example of drawing molecules."}, + {"ode", smgl_ode, mmgl_ode, "Example of phase plain created by @ref{ode} solving, contour lines (@ref{cont}) and @ref{flow} threads."}, + {"ohlc", smgl_ohlc, mmgl_ohlc, "Function @ref{ohlc} draw Open-High-Low-Close diagram. This diagram show vertical line for between maximal(high) and minimal(low) values, as well as horizontal lines before/after vertical line for initial(open)/final(close) values of some process."}, + {"param1", smgl_param1, mmgl_param1, "Example of parametric plots for 1D data."}, + {"param2", smgl_param2, mmgl_param2, "Example of parametric plots for 2D data."}, + {"param3", smgl_param3, mmgl_param3, "Example of parametric plots for 3D data."}, + {"paramv", smgl_paramv, mmgl_paramv, "Example of parametric plots for vector fields."}, + {"parser", smgl_parser, mmgl_parser, "Basic MGL script."}, + {"pde", smgl_pde, mmgl_pde, "Example of @ref{pde} solver."}, + {"pendelta", smgl_pendelta, mmgl_pendelta, "Example of @ref{pendelta} for lines and glyphs smoothing."}, + {"pipe", smgl_pipe, mmgl_pipe, "Function @ref{pipe} is similar to @ref{flow} but draw pipes (tubes) which radius is proportional to the amplitude of vector field. The color scheme is used for coloring (see @ref{Color scheme}). At this warm color corresponds to normal flow (like attractor), cold one corresponds to inverse flow (like source)."}, + {"plot", smgl_plot, mmgl_plot, "Function @ref{plot} is most standard way to visualize 1D data array. By default, @code{Plot} use colors from palette. However, you can specify manual color/palette, and even set to use new color for each points by using @samp{!} style. Another feature is @samp{ } style which draw only markers without line between points."}, + {"pmap", smgl_pmap, mmgl_pmap, "Function @ref{pmap} draw Poincare map -- show intersections of the curve and the surface."}, + {"primitives", smgl_primitives, mmgl_primitives , "Example of primitives: @ref{line}, @ref{curve}, @ref{rhomb}, @ref{ellipse}, @ref{face}, @ref{sphere}, @ref{drop}, @ref{cone}."}, + {"projection", smgl_projection, mmgl_projection , "Example of plot projection (@ref{ternary}=4)."}, + {"projection5", smgl_projection5, mmgl_projection5 , "Example of plot projection in ternary coordinates (@ref{ternary}=5)."}, + {"pulse", smgl_pulse, mmgl_pulse , "Example of @ref{pulse} parameter determining."}, + {"qo2d", smgl_qo2d, mmgl_qo2d, "Example of PDE solving by quasioptical approach @ref{qo2d}."}, + {"quality0", smgl_quality0, mmgl_quality0, "Show all kind of primitives in @ref{quality}=0."}, + {"quality1", smgl_quality1, mmgl_quality1, "Show all kind of primitives in @ref{quality}=1."}, + {"quality2", smgl_quality2, mmgl_quality2, "Show all kind of primitives in @ref{quality}=2."}, + {"quality4", smgl_quality4, mmgl_quality4, "Show all kind of primitives in @ref{quality}=4."}, + {"quality5", smgl_quality5, mmgl_quality5, "Show all kind of primitives in @ref{quality}=5."}, + {"quality6", smgl_quality6, mmgl_quality6, "Show all kind of primitives in @ref{quality}=6."}, + {"quality8", smgl_quality8, mmgl_quality8, "Show all kind of primitives in @ref{quality}=8."}, + {"radar", smgl_radar, mmgl_radar, "The @ref{radar} plot is variant of @ref{plot}, 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 @ref{plot} in parametric form with @code{x=r*cos(fi); y=r*sin(fi);}."}, + {"refill", smgl_refill, mmgl_refill, "Example of @ref{refill} and @ref{gspline}."}, + {"region", smgl_region, mmgl_region, "Function @ref{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 y1Create(n,3); - if(x1) x1->Create(n); if(x2) x2->Create(n); - if(y1) y1->Create(n); if(y2) y2->Create(n); + if(x1) x1->Create(n); + if(x2) x2->Create(n); + if(y1) y1->Create(n); + if(y2) y2->Create(n); for(long i=0;iCreate(n,m); if(b) b->Create(n,m); + if(a) a->Create(n,m); + if(b) b->Create(n,m); if(v) { v->Create(9); v->Fill(-1,1); } for(long j=0;ja[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); } @@ -464,11 +461,12 @@ void mgls_prepare2d(mglData *a, mglData *b, mglData *v) void mgls_prepare3d(mglData *a, mglData *b) { long n=61,m=50,l=40; - if(a) a->Create(n,m,l); if(b) b->Create(n,m,l); + if(a) a->Create(n,m,l); + if(b) b->Create(n,m,l); for(long k=0;ka[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)); } @@ -477,11 +475,12 @@ void mgls_prepare3d(mglData *a, mglData *b) void mgls_prepare2v(mglData *a, mglData *b) { long n=20,m=30; - if(a) a->Create(n,m); if(b) b->Create(n,m); + if(a) a->Create(n,m); + if(b) b->Create(n,m); for(long j=0;ja[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); } @@ -496,14 +495,7 @@ void mgls_prepare3v(mglData *ex, mglData *ey, mglData *ez) for(long k=0;ka[i0]=z*y*r2*r2; - ey->a[i0]=x*y*r2*r2+1; - ez->a[i0]=y*x*r2*r2;*/ -/* ex->a[i0]=3*z; - ey->a[i0]=1; - ez->a[i0]=-3*x;*/ + long i0 = i+n*(j+k*n); double r1 = pow(x*x+y*y+(z-z0)*(z-z0)+0.03,1.5); double r2 = pow(x*x+y*y+(z+z0)*(z+z0)+0.03,1.5); ex->a[i0]=0.2*x/r1 - 0.2*x/r2; diff --git a/examples/wx_example.cpp b/examples/wx_example.cpp index 34b1c72..2f82765 100644 --- a/examples/wx_example.cpp +++ b/examples/wx_example.cpp @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include +#undef _ #include "mgl2/wx.h" //----------------------------------------------------------------------------- int test_wnd(mglGraph *gr); diff --git a/fonts/CMakeLists.txt b/fonts/CMakeLists.txt index f24af56..f529c18 100644 --- a/fonts/CMakeLists.txt +++ b/fonts/CMakeLists.txt @@ -1,20 +1,23 @@ -add_executable(make_bin make_bin.cpp) -target_link_libraries(make_bin mgl-static ${getopt_lib-static}) +include_directories( ${MathGL2_SOURCE_DIR}/include ${MathGL2_BINARY_DIR}/include) +set(hdrF ../include/mgl2/font.h ../include/mgl2/define.h ${MathGL2_BINARY_DIR}/include/mgl2/config.h) +add_executable(make_bin make_bin.cpp ../src/font.cpp ${hdrF}) +#target_link_libraries(make_bin mgl-static ${getopt_lib-static}) +target_link_libraries(make_bin ${MGL_DEP_LIBS}) set(MGL_FONTS STIX adventor bonum cursor heroscn heros pagella schola termes) set(MGL_FONTS_BIN ) set(MGL_FONTS_SRC ) foreach(SAMPLE ${MGL_FONTS}) - set(MGL_FONTS_BIN ${MGL_FONTS_BIN} ${MathGL_BINARY_DIR}/fonts/${SAMPLE}.vfmb) - add_custom_command(OUTPUT ${MathGL_BINARY_DIR}/fonts/${SAMPLE}.vfmb - COMMAND make_bin -p ${MathGL_SOURCE_DIR}/fonts/ -o ${MathGL_BINARY_DIR}/fonts/${SAMPLE}.vfmb ${SAMPLE} + set(MGL_FONTS_BIN ${MGL_FONTS_BIN} ${MathGL2_BINARY_DIR}/fonts/${SAMPLE}.vfmb) + add_custom_command(OUTPUT ${MathGL2_BINARY_DIR}/fonts/${SAMPLE}.vfmb + COMMAND make_bin -p ${MathGL2_SOURCE_DIR}/fonts/ -o ${MathGL2_BINARY_DIR}/fonts/${SAMPLE}.vfmb ${SAMPLE} DEPENDS ${SAMPLE}.vfm make_bin ) endforeach(SAMPLE) add_custom_target(fonts ALL DEPENDS ${MGL_FONTS_BIN}) -install(DIRECTORY ${MathGL_BINARY_DIR}/fonts/ DESTINATION ${MGL_FONT_PATH} +install(DIRECTORY ${MathGL2_BINARY_DIR}/fonts/ DESTINATION ${MGL_FONT_PATH} PATTERN "*[mM]ake*" EXCLUDE PATTERN ".svn" EXCLUDE PATTERN "*.vfmb") diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index cbde2e5..b3e2744 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,4 +1,5 @@ -configure_file(${MathGL_SOURCE_DIR}/include/config.h.in ${MathGL_BINARY_DIR}/include/mgl2/config.h) +configure_file(${MathGL2_SOURCE_DIR}/include/config.h.in ${MathGL2_BINARY_DIR}/include/mgl2/config.h) +configure_file(${MathGL2_SOURCE_DIR}/include/build.h.in ${MathGL2_BINARY_DIR}/include/mgl2/build.h) install(DIRECTORY mgl2/ DESTINATION ${MGL_INCLUDE_PATH} PATTERN ".svn" EXCLUDE @@ -14,7 +15,7 @@ install(DIRECTORY mgl2/ DESTINATION ${MGL_INCLUDE_PATH} PATTERN "*.pas" PATTERN "*.h") -install(FILES ${MathGL_BINARY_DIR}/include/mgl2/config.h DESTINATION ${MGL_INCLUDE_PATH}) +install(FILES ${MathGL2_BINARY_DIR}/include/mgl2/config.h DESTINATION ${MGL_INCLUDE_PATH}) if(MGL_HAVE_FLTK) install(FILES mgl2/fltk.h DESTINATION ${MGL_INCLUDE_PATH}) endif(MGL_HAVE_FLTK) diff --git a/include/build.h.in b/include/build.h.in new file mode 100644 index 0000000..f791535 --- /dev/null +++ b/include/build.h.in @@ -0,0 +1,6 @@ +#ifndef _MGL_BUILD_H_ +#define _MGL_BUILD_H_ + +#define MGL_BUILD_DATE "${MathGL_DATE}" + +#endif diff --git a/include/config.h.in b/include/config.h.in index 233e312..6367a08 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -1,7 +1,12 @@ #ifndef _MGL_CONFIG_H_ #define _MGL_CONFIG_H_ -#define MGL_VER2 ${MathGL_VERSION_MINOR} // minor version of MathGL 2.* (like 1.3 for v.2.1.3) +#define MGL_VER2 ${MathGL_VERSION_MINOR}.${MathGL_PATCH_VERSION} // minor version of MathGL 2.* (like 1.3 for v.2.1.3) +#define MGL_VER_MAJOR ${MathGL_VERSION_MAJOR} +#define MGL_VER_MINOR ${MathGL_VERSION_MINOR} +#define MGL_VER_PATCH ${MathGL_PATCH_VERSION} +#define MGL_VERSION (${MathGL_VERSION_MAJOR}000+${MathGL_VERSION_MINOR}.${MathGL_PATCH_VERSION}) +#define MGL_VER_STRING "${MathGL_VERSION_MAJOR}.${MathGL_VERSION_MINOR}.${MathGL_PATCH_VERSION}" #define MGL_USE_DOUBLE ${MGL_USE_DOUBLE} @@ -10,17 +15,16 @@ #else #define MGL_DEF_FONT_NAME "${MGL_DEF_FONT}" #endif +#define MGL_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}" #if defined(_MSC_VER) || defined(__BORLANDC__) #define MGL_SYS_NAN 0 -#define MGL_HAVE_TYPEOF 0 #define MGL_HAVE_PTHREAD 0 #define MGL_HAVE_PTHR_WIDGET 0 #define MGL_HAVE_ATTRIBUTE 0 #define MGL_HAVE_C99_COMPLEX 0 #else -#define MGL_HAVE_TYPEOF ${MGL_HAVE_TYPEOF} -#define MGL_SYS_NAN ${MGL_HAVE_NAN_INF} +#define MGL_SYS_NAN ${MGL_HAVE_NAN_INF} #define MGL_HAVE_PTHREAD ${MGL_HAVE_PTHREAD} #define MGL_HAVE_PTHR_WIDGET ${MGL_HAVE_PTHR_WIDGET} #define MGL_HAVE_ATTRIBUTE ${MGL_HAVE_ATTRIBUTE} @@ -40,6 +44,8 @@ #define MGL_HAVE_PDF ${MGL_HAVE_PDF} #define MGL_HAVE_HDF4 ${MGL_HAVE_HDF4} #define MGL_HAVE_HDF5 ${MGL_HAVE_HDF5} +#define MGL_USE_GETTEXT ${MGL_USE_LIBINTL} #define MGL_FONT_PATH "${MGL_FONT_PATH}" +#define MGL_HAVE_FL_COPY ${MGL_HAVE_FL_COPY} #endif diff --git a/include/mgl2/Fl_MathGL.h b/include/mgl2/Fl_MathGL.h index 372bae2..b533c48 100644 --- a/include/mgl2/Fl_MathGL.h +++ b/include/mgl2/Fl_MathGL.h @@ -30,6 +30,7 @@ #include #include #include +#include #include class mglCanvas; //----------------------------------------------------------------------------- @@ -41,64 +42,105 @@ public: Fl_Valuator *tet_val; ///< pointer to external tet-angle validator Fl_Valuator *phi_val; ///< pointer to external phi-angle validator mglCanvas *gr; ///< Built-in mglCanvas instance (mglCanvasFLTK is used by default) + std::string prim; ///< manual primitives + bool use_pthr; ///< use pthread for update plot Fl_MathGL(int x, int y, int w, int h, const char *label=0); virtual ~Fl_MathGL(); + + /// Set drawing functions and its parameter + inline void set_draw(int (*func)(mglBase *gr, void *par), void *par) + { if(draw_cl) delete draw_cl; draw_cl=0; draw_func=func; draw_par=par; } + /// Set drawing functions pointed on mglGraph + inline void set_draw(int (*dr)(mglGraph *gr)) + { set_draw(dr?mgl_draw_graph:0,(void*)dr); } + /// Set drawing based on instance of mglDraw class + inline void set_draw(mglDraw *dr) + { if(draw_cl) delete draw_cl; draw_cl=dr; draw_func=0; } + /// Set function for parameters + inline void set_prop(void (*func)(char id, const char *val, void *par), void *par) + { prop_func=func; prop_par=par; } + /// Refresh image (without executing update) + void refresh(); /// Update (redraw) plot virtual void update(); /// Set angles for additional plot rotation - inline void set_angle(mreal t, mreal p){ tet = t; phi = p; } + inline void set_angle(double t, double p){ tet = t; phi = p; } /// Set bitwise flags for general state (1-Alpha, 2-Light) inline void set_flag(int f) { flag = f; } /// Set flags for handling mouse - void set_graph(HMGL gr); ///< Set grapher object + void set_state(bool z, bool r, bool g=false) + { zoom = z; rotate = r; grid = g; } + /// Set zoom in/out region + inline void set_zoom(double X1, double Y1, double X2, double Y2) + { x1 = X1; x2 = X2; y1 = Y1; y2 = Y2; update(); } + /// Get zoom region + inline void get_zoom(double *X1, double *Y1, double *X2, double *Y2) + { *X1 = x1; *X2 = x2; *Y1 = y1; *Y2 = y2; } + /// Set popup menu pointer + inline void set_popup(const Fl_Menu_Item *pmenu, Fl_Widget *wdg, void *v) + { popup = pmenu; wpar = wdg; vpar = v; } + + /// Set grapher object instead of built-in one. + /// NOTE: Fl_MathGL will automatically delete this object + void set_graph(HMGL gr); + /// Set grapher object instead of built-in one. + /// NOTE: Fl_MathGL will automatically delete this object inline void set_graph(mglGraph *Gr) { set_graph(Gr->Self()); } /// Get pointer to grapher inline HMGL get_graph() { return (HMGL)gr; } + /// Get mglDraw pointer or NULL inline mglDraw *get_class() { mglDraw *d=0; if(draw_func==mgl_draw_class) d = (mglDraw*)draw_par; - if(draw_cl) d = draw_cl; return d; } - /// Set drawing functions and its parameter - inline void set_draw(int (*func)(mglBase *gr, void *par), void *par) - { if(draw_cl) delete draw_cl; draw_cl=0; draw_func=func; draw_par=par; } - inline void set_draw(mglDraw *dr) { if(draw_cl) delete draw_cl; draw_cl=dr; draw_func=0; } - inline void set_draw(int (*dr)(mglGraph *gr)) - { set_draw(dr?mgl_draw_graph:0,(void*)dr); } - void set_state(bool z, bool r) { zoom = z; rotate = r; } - /// Set zoom in/out region - inline void set_zoom(mreal X1, mreal Y1, mreal X2, mreal Y2) - { x1 = X1; x2 = X2; y1 = Y1; y2 = Y2; update(); } - /// Get zoom region - inline void get_zoom(mreal *X1, mreal *Y1, mreal *X2, mreal *Y2) - { *X1 = x1; *X2 = x2; *Y1 = y1; *Y2 = y2; } - /// Set popup menu pointer - inline void set_popup(const Fl_Menu_Item *pmenu, Fl_Widget *wdg, void *v) - { popup = pmenu; wpar = wdg; vpar = v; } - inline void zoom_region(mreal xx1,mreal xx2,mreal yy1, mreal yy2) - { x1=xx1; y1=yy1; x2=xx2; y2=yy2; } + if(draw_cl) d = draw_cl; + return d; } + inline void set_param(char id, const char *val) + { mglDraw *d=get_class(); if(d) d->Param(id,val); else prop_func(id,val,prop_par); } + + /// Show window with warnings after script parsing + inline void set_show_warn(bool s) { show_warn=s; } + /// Ask to stop of script parsing void stop(bool stop=true); + /// Enable/disable key handling as in mglview (default is false) + inline void set_handle_key(bool val) { handle_keys=true; } + /// Get id of last clicked object + inline int get_last_id() { return last_id; } + void draw_plot(); ///< Single thread drawing itself + /// Check if script is parsing now or not + inline bool running() { return run; } protected: - void *draw_par; ///< Parameters for drawing function mglCanvasWnd::DrawFunc. + void *draw_par; ///< Parameters for drawing function draw_func(). /// Drawing function for window procedure. It should return the number of frames. int (*draw_func)(mglBase *gr, void *par); + void *prop_par; ///< Parameters for prop_func(). + /// Function for setting properties. + void (*prop_func)(char id, const char *val, void *par); mglDraw *draw_cl; + int last_id; ///< last selected object id const Fl_Menu_Item *popup; ///< pointer to popup menu items Fl_Widget *wpar; ///< widget for popup menu void *vpar; ///< parameter for popup menu - mreal tet,phi; ///< rotation angles + double tet,phi; ///< rotation angles bool rotate; ///< flag for handle mouse bool zoom; ///< flag for zoom by mouse - bool wire; - mreal x1,x2,y1,y2; ///< zoom region + bool grid; ///< flag to draw grid and edit prim + bool show_warn; ///< show window with warnings + bool handle_keys; + double x1,x2,y1,y2; ///< zoom region int flag; ///< bitwise flag for general state (1-Alpha, 2-Light) int x0,y0,xe,ye; ///< mouse position - char pos[128]; + char mouse_pos[128]; + bool run; ///< flag that drawing in progress + const unsigned char *img; ///< image for drawing +#if (MGL_HAVE_PTHREAD|MGL_HAVE_PTHR_WIDGET) + pthread_t thr; ///< main thread for drawing +#endif virtual void draw(); ///< quick drawing function int handle(int code); ///< handle mouse events @@ -118,25 +160,63 @@ public: mreal (*delay)(void*); ///< Callback function for delay void (*reload)(void*); ///< Callback function for reloading - void toggle_alpha() { toggle(alpha, alpha_bt, "Graphics/Alpha"); } - void toggle_light() { toggle(light, light_bt, "Graphics/Light"); } - void toggle_sshow() { toggle(sshow, anim_bt, "Graphics/Slideshow"); } - void toggle_grid() { toggle(grid, grid_bt, "Graphics/Grid"); } + /// Toggle transparency (alpha) button + void toggle_alpha() { toggle(alpha, alpha_bt, _("Graphics/Alpha")); } + /// Toggle lighting button + void toggle_light() { toggle(light, light_bt, _("Graphics/Light")); } + /// Toggle slideshow button + void toggle_sshow() { toggle(sshow, anim_bt, _("Graphics/Animation/Slideshow")); } + /// Toggle grid drawing button + void toggle_grid() { toggle(grid, grid_bt, _("Graphics/Grid")); } + /// Toggle mouse zoom button void toggle_zoom() { toggle(zoom, zoom_bt); } + /// Toggle mouse rotate button void toggle_rotate(){ toggle(rotate, rotate_bt); } + /// Switch off zoom button void setoff_zoom() { setoff(zoom, zoom_bt); } + /// Switch off rotate button void setoff_rotate(){ setoff(rotate, rotate_bt); } + /// Check if slideshow running bool is_sshow() { return sshow; } - void toggle_pause() { toggle(pauseC, pause_bt, "Graphics/Pause calc"); exec_pause(); } + /// Toggle pause calculation button + void toggle_pause() { toggle(pauseC, pause_bt, _("Graphics/Pause calc")); exec_pause(); } + /// Adjust image sizes to the current widget sizes void adjust() { mgl_set_size(FMGL->get_graph(),scroll->w(),scroll->h()); FMGL->size(scroll->w(),scroll->h()); update(); } + /// Get current grapher + HMGL get_graph() { return FMGL->get_graph(); } + /// Update picture by calling user drawing function + void update(); + + /// Create and show custom dialog + void dialog(const char *ids, char const * const *args, const char *title="") + { + if(!ids || *ids==0) return; + dlg_window(title); + for(int i=0;ids[i];i++) add_widget(ids[i], args[i]); + dlg_finish(); dlg_wnd->show(); + } + void dialog(const std::string &ids, const std::vector &args, const char *title="") + { + std::vector buf; buf.reserve(args.size()); + for(size_t i=0;ishow(); + } + void dlg_window(const char *title=""); ///< Create/label dialog window + void add_widget(char id, const char *args); ///< Add widget to dialog + void dlg_show() { dlg_finish(); dlg_wnd->show(); } ///< Show window + void dlg_hide() { dlg_wnd->hide(); } ///< Close window + void get_values(); ///< Get all values from dialog window + void set_progress(int value, int maximal); ///< Set progress Fl_MGLView(int x, int y, int w, int h, const char *label=0); virtual ~Fl_MGLView(); - void update(); ///< Update picture by calling user drawing function protected: Fl_Button *alpha_bt, *light_bt, *rotate_bt, *anim_bt, *zoom_bt, *grid_bt, *pause_bt; -// Fl_Counter *tet, *phi; + Fl_Progress *progress; int grid, alpha, light; ///< Current states of wire, alpha, light switches (toggle buttons) int sshow, rotate, zoom;///< Current states of slideshow, rotate, zoom switches (toggle buttons) @@ -145,8 +225,21 @@ protected: void toggle(int &val, Fl_Button *b, const char *txt=NULL); void setoff(int &val, Fl_Button *b, const char *txt=NULL); void exec_pause(); + + Fl_Double_Window *dlg_wnd; ///< Dialog window itself + std::vector strs; ///< Strings for widget labels + bool dlg_done; ///< Dialog is created + int dlg_ind; ///< Current index of widget + std::vector dlg_kind; ///< Kind of elements + std::vector dlg_wdgt; ///< List of widgets + std::vector dlg_ids; ///< Id of elements + std::vector dlg_vals; ///< resulting strings + void dlg_finish(); ///< Finish dialog window creation + }; //----------------------------------------------------------------------------- void MGL_EXPORT mgl_makemenu_fltk(Fl_Menu_ *m, Fl_MGLView *w); +MGL_EXPORT const char *mgl_file_chooser(const char *mess, const char *filter="", bool save=false); +MGL_EXPORT const char *mgl_dir_chooser(const char *mess, const char *path); //----------------------------------------------------------------------------- #endif diff --git a/include/mgl2/abstract.h b/include/mgl2/abstract.h index 861aeb1..515b814 100644 --- a/include/mgl2/abstract.h +++ b/include/mgl2/abstract.h @@ -1,295 +1,400 @@ -/*************************************************************************** - * abstract.h is part of Math Graphic Library - * Copyright (C) 2007-2016 Alexey Balakin * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License as * - * published by the Free Software Foundation; either version 3 of the * - * License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef _MGL_ABSTRACT_H_ -#define _MGL_ABSTRACT_H_ - -#include "mgl2/define.h" -//----------------------------------------------------------------------------- -#ifdef __cplusplus -#include "mgl2/type.h" -#define MGL_TO_WCS(str,code) if(str && *str){size_t s=mbstowcs(0,str,0); wchar_t *wcs=new wchar_t[s+1]; mbstowcs(wcs,str,s); wcs[s]=0; code; delete []wcs;}else{const wchar_t *wcs=L""; code;} -//----------------------------------------------------------------------------- -class mglBase; -class mglData; -class mglDataA; -class mglDataC; -class mglParser; -class mglFormula; -class mglFormulaC; -class mglFont; -typedef mglBase* HMGL; -typedef mglData* HMDT; -typedef mglDataC* HADT; -typedef mglParser* HMPR; -typedef mglFormula* HMEX; -typedef mglFormulaC* HAEX; -typedef const mglDataA* HCDT; - -std::string MGL_EXPORT mgl_data_to_string(HCDT d, long ns); -std::string MGL_EXPORT mgl_datac_to_string(HCDT d, long ns); -extern "C" { - -#else -#define mglDataA void -typedef void *HMGL; -typedef void *HMDT; -typedef void *HADT; -typedef void *HMEX; -typedef void *HAEX; -typedef void *HMPR; -typedef const void *HCDT; -#endif - -/// Set seed for random numbers -void MGL_EXPORT mgl_srnd(long seed); -void MGL_EXPORT mgl_srnd_(int *seed); -/// Get random number -double MGL_EXPORT mgl_rnd(); -double MGL_EXPORT mgl_rnd_(); - -/// Set name for data variable (can be used in mgl_formula_calc() or in MGL scripts) -void MGL_EXPORT mgl_data_set_name(mglDataA *dat, const char *name); -void MGL_EXPORT mgl_data_set_name_(uintptr_t *dat, const char *name,int); -void MGL_EXPORT mgl_data_set_name_w(mglDataA *dat, const wchar_t *name); -/// Set callback function which is called at deleting variable -void MGL_EXPORT mgl_data_set_func(mglDataA *dat, void (*func)(void *), void *par); - -/// Save whole data array (for ns=-1) or only ns-th slice to text file -void MGL_EXPORT mgl_data_save(HCDT dat, const char *fname,long ns); -void MGL_EXPORT mgl_data_save_(uintptr_t *dat, const char *fname,int *ns,int); -/// Export data array (for ns=-1) or only ns-th slice to PNG file according color scheme -void MGL_EXPORT mgl_data_export(HCDT dat, const char *fname, const char *scheme,mreal v1,mreal v2,long ns); -void MGL_EXPORT mgl_data_export_(uintptr_t *dat, const char *fname, const char *scheme,mreal *v1,mreal *v2,int *ns,int,int); -/// Save data to HDF file -void MGL_EXPORT mgl_data_save_hdf(HCDT d,const char *fname,const char *data,int rewrite); -void MGL_EXPORT mgl_data_save_hdf_(uintptr_t *d, const char *fname, const char *data, int *rewrite,int l,int n); -/// Get information about the data (sizes and momentum) to string -MGL_EXPORT const char *mgl_data_info(HCDT dat); -int MGL_EXPORT mgl_data_info_(uintptr_t *dat, char *out, int len); -/// Put HDF data names into buf as '\t' separated. -int MGL_EXPORT mgl_datas_hdf(const char *fname, char *buf, long size); -int MGL_EXPORT mgl_datas_hdf_(const char *fname, char *buf, int l, int size); - -/// Get maximal value of the data -mreal MGL_EXPORT mgl_data_max(HCDT dat); -mreal MGL_EXPORT mgl_data_max_(uintptr_t *dat); -/// Get maximal value of the data which is less than 0 -mreal MGL_EXPORT mgl_data_neg_max(HCDT dat); -mreal MGL_EXPORT mgl_data_neg_max_(uintptr_t *dat); -/// Get minimal value of the data -mreal MGL_EXPORT mgl_data_min(HCDT dat); -mreal MGL_EXPORT mgl_data_min_(uintptr_t *dat); -/// Get minimal value of the data which is larger than 0 -mreal MGL_EXPORT mgl_data_pos_min(HCDT dat); -mreal MGL_EXPORT mgl_data_pos_min_(uintptr_t *dat); -/// Find position (after specified in i,j,k) of first nonzero value of formula -mreal MGL_EXPORT mgl_data_first(HCDT dat, const char *cond, long *i, long *j, long *k); -mreal MGL_EXPORT mgl_data_first_(uintptr_t *dat, const char *cond, int *i, int *j, int *k, int); -/// Find position (before specified in i,j,k) of last nonzero value of formula -mreal MGL_EXPORT mgl_data_last(HCDT dat, const char *cond, long *i, long *j, long *k); -mreal MGL_EXPORT mgl_data_last_(uintptr_t *dat, const char *cond, int *i, int *j, int *k, int); -/// Find position of first in direction 'dir' nonzero value of formula -long MGL_EXPORT mgl_data_find(HCDT dat, const char *cond, char dir, long i, long j, long k); -int MGL_EXPORT mgl_data_find_(uintptr_t *dat, const char *cond, char *dir, int *i, int *j, int *k, int,int); -/// Find if any nonzero value of formula -int MGL_EXPORT mgl_data_find_any(HCDT dat, const char *cond); -int MGL_EXPORT mgl_data_find_any_(uintptr_t *dat, const char *cond, int); -/// Get maximal value of the data and its position -mreal MGL_EXPORT mgl_data_max_int(HCDT dat, long *i, long *j, long *k); -mreal MGL_EXPORT mgl_data_max_int_(uintptr_t *dat, int *i, int *j, int *k); -/// Get maximal value of the data and its approximated position -mreal MGL_EXPORT mgl_data_max_real(HCDT dat, mreal *x, mreal *y, mreal *z); -mreal MGL_EXPORT mgl_data_max_real_(uintptr_t *dat, mreal *x, mreal *y, mreal *z); -/// Get minimal value of the data and its position -mreal MGL_EXPORT mgl_data_min_int(HCDT dat, long *i, long *j, long *k); -mreal MGL_EXPORT mgl_data_min_int_(uintptr_t *dat, int *i, int *j, int *k); -/// Get minimal value of the data and its approximated position -mreal MGL_EXPORT mgl_data_min_real(HCDT dat, mreal *x, mreal *y, mreal *z); -mreal MGL_EXPORT mgl_data_min_real_(uintptr_t *dat, mreal *x, mreal *y, mreal *z); -/// Get "energy and find 4 momenta of data: median, width, skewness, kurtosis -mreal MGL_EXPORT mgl_data_momentum_val(HCDT d, char dir, mreal *m, mreal *w, mreal *s, mreal *k); -mreal MGL_EXPORT mgl_data_momentum_val_(uintptr_t *dat, char *dir, mreal *m, mreal *w, mreal *s, mreal *k,int); - -/// Interpolate by linear function the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] -mreal MGL_EXPORT mgl_data_linear(HCDT dat, mreal x,mreal y,mreal z); -mreal MGL_EXPORT mgl_data_linear_(uintptr_t *dat, mreal *x,mreal *y,mreal *z); -/// Interpolate by linear function the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] -mreal MGL_EXPORT mgl_data_linear_ext(HCDT dat, mreal x,mreal y,mreal z, mreal *dx,mreal *dy,mreal *dz); -mreal MGL_EXPORT mgl_data_linear_ext_(uintptr_t *dat, mreal *x,mreal *y,mreal *z, mreal *dx,mreal *dy,mreal *dz); - -/// Internal function for (un-)locking mutex in mglStack -void MGL_EXPORT mgl_mutex_lock(void *); -void MGL_EXPORT mgl_mutex_unlock(void *); - -//----------------------------------------------------------------------------- -/// Callback function for asking user a question. Result shouldn't exceed 1024. -extern MGL_EXPORT void (*mgl_ask_func)(const wchar_t *quest, wchar_t *res); -//----------------------------------------------------------------------------- -#ifdef __cplusplus -} -/// Abstract class for data array -class MGL_EXPORT mglDataA -{ -public: - std::wstring s; ///< Data name - bool temp; ///< This is temporary variable - void (*func)(void *); ///< Callback function for destroying - void *o; ///< Pointer to external object - - mglDataA() { temp=false; func=0; o=0; } - virtual ~mglDataA() { if(func) func(o); } - virtual void set_v(mreal /*val*/, long /*i*/,long /*j*/=0,long /*k*/=0) {} - /// Get the interpolated value and its derivatives in given data cell without border checking - virtual mreal valueD(mreal x,mreal y=0,mreal z=0,mreal *dx=0,mreal *dy=0,mreal *dz=0) const =0; - /// Get the interpolated value in given data cell without border checking - virtual mreal value(mreal x,mreal y=0,mreal z=0) const =0; - /// Interpolate by linear function the data to given point - inline mreal linear(mreal x,mreal y=0,mreal z=0) const - { return mgl_data_linear_ext(this,x,y,z,0,0,0); } - /// Interpolate by linear function the data to given point and get the gradient - inline mreal linearD(mreal x,mreal y=0,mreal z=0,mreal *dx=0,mreal *dy=0,mreal *dz=0) const - { return mgl_data_linear_ext(this,x,y,z,dx,dy,dz); } - virtual mreal v(long i,long j=0,long k=0) const = 0; - virtual mreal vthr(long i) const - { return v(i%GetNx(), (i/GetNx())%GetNy(), i/(GetNx()*GetNy())); } - virtual dual vc(long i,long j=0,long k=0) const { return v(i,j,k); } - virtual dual vcthr(long i) const { return vthr(i); } - virtual long GetNx() const = 0; - virtual long GetNy() const = 0; - virtual long GetNz() const = 0; - inline long GetNN() const { return GetNx()*GetNy()*GetNz(); } - virtual mreal dvx(long i,long j=0,long k=0) const = 0; -// { return i>0 ? (i0 ? (j0 ? (k1?GetNx()-1:1; dif.y*=GetNy()>1?GetNy()-1:1; dif.z*=GetNz()>1?GetNz()-1:1; return res; } - - /// Interpolate by linear function the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] - inline mreal Linear(mreal x,mreal y=0,mreal z=0) const - { return mgl_data_linear_ext(this,x,y,z,0,0,0); } - /// Interpolate by line the data to given point x,\a y,\a z which normalized in range [0, 1] - inline mreal Linear1(mreal x,mreal y=0,mreal z=0) const - { return mgl_data_linear_ext(this,x*(GetNx()-1),y*(GetNy()-1),z*(GetNz()-1),0,0,0); } - /// Interpolate by linear function the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] - inline mreal Linear(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const - { return mgl_data_linear_ext(this,x,y,z, &(dif.x),&(dif.y), &(dif.z)); } - /// Interpolate by line the data and return its derivatives at given point x,\a y,\a z which normalized in range [0, 1] - inline mreal Linear1(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const - { mreal res=mgl_data_linear_ext(this,x*(GetNx()-1),y*(GetNy()-1),z*(GetNz()-1), &(dif.x),&(dif.y), &(dif.z)); - dif.x*=GetNx()>1?GetNx()-1:1; dif.y*=GetNy()>1?GetNy()-1:1; dif.z*=GetNz()>1?GetNz()-1:1; return res; } -}; -//----------------------------------------------------------------------------- -/// Structure for color ID -struct MGL_EXPORT mglColorID -{ - char id; - mglColor col; -}; -MGL_EXPORT extern mglColorID mglColorIds[31]; -MGL_EXPORT extern std::string mglGlobalMess; ///< Buffer for receiving global messages -//----------------------------------------------------------------------------- -#endif - -#ifdef MGL_SRC -#define _Da_(d) (*((const mglDataA *)(d))) -#define _DA_(a) ((const mglDataA *)*(a)) -#define _GR_ ((mglBase *)(*gr)) -//#define _D_(d) *((mglData *)*(d)) -#define _DM_(a) ((mglData *)*(a)) -#define _DT_ ((mglData *)*d) -#endif - -#endif +/*************************************************************************** + * abstract.h is part of Math Graphic Library + * Copyright (C) 2007-2016 Alexey Balakin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef _MGL_ABSTRACT_H_ +#define _MGL_ABSTRACT_H_ + +#include "mgl2/define.h" +//----------------------------------------------------------------------------- +#ifdef __cplusplus +#include "mgl2/type.h" +#define MGL_TO_WCS(str,code) if(str && *str){size_t s=mbstowcs(0,str,0); wchar_t *wcs=new wchar_t[s+1]; mbstowcs(wcs,str,s); wcs[s]=0; code; delete []wcs;}else{const wchar_t *wcs=L""; code;} +//----------------------------------------------------------------------------- +class mglBase; +class mglData; +class mglDataA; +class mglDataC; +class mglParser; +class mglFormula; +class mglFormulaC; +class mglFont; +typedef mglBase* HMGL; +typedef mglData* HMDT; +typedef mglDataC* HADT; +typedef mglParser* HMPR; +typedef mglFormula* HMEX; +typedef mglFormulaC* HAEX; +typedef const mglDataA* HCDT; +//----------------------------------------------------------------------------- +std::string MGL_EXPORT mgl_data_to_string(HCDT d, long ns); +std::string MGL_EXPORT mgl_datac_to_string(HCDT d, long ns); +/// Get section separated by symbol ch. This is analog of QString::section(). +std::string MGL_EXPORT mgl_str_arg(const std::string &str, char ch, int n1, int n2=-1); +/// Get sections separated by symbol ch +std::vector MGL_EXPORT mgl_str_args(const std::string &str, char ch); +/// Get string from real number +std::string MGL_EXPORT mgl_str_num(double val); +/// Get string from complex number +std::string MGL_EXPORT mgl_str_num(dual val); +//----------------------------------------------------------------------------- + +extern "C" { + +#else +#define mglDataA void +#define mglNum void +typedef void *HMGL; +typedef void *HMDT; +typedef void *HADT; +typedef void *HMEX; +typedef void *HAEX; +typedef void *HMPR; +typedef const void *HCDT; +#endif + +/// Set buffer size for number of primitives as (1<0 ? (i0 ? (j0 ? (k1?GetNx()-1:1; dif.y*=GetNy()>1?GetNy()-1:1; dif.z*=GetNz()>1?GetNz()-1:1; return res; } + + /// Interpolate by linear function the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] + inline mreal Linear(mreal x,mreal y=0,mreal z=0) const + { return mgl_data_linear_ext(this,x,y,z,0,0,0); } + /// Interpolate by line the data to given point x,\a y,\a z which normalized in range [0, 1] + inline mreal Linear1(mreal x,mreal y=0,mreal z=0) const + { return mgl_data_linear_ext(this,x*(GetNx()-1),y*(GetNy()-1),z*(GetNz()-1),0,0,0); } + /// Interpolate by linear function the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] + inline mreal Linear(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const + { return mgl_data_linear_ext(this,x,y,z, &(dif.x),&(dif.y), &(dif.z)); } + /// Interpolate by line the data and return its derivatives at given point x,\a y,\a z which normalized in range [0, 1] + inline mreal Linear1(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const + { mreal res=mgl_data_linear_ext(this,x*(GetNx()-1),y*(GetNy()-1),z*(GetNz()-1), &(dif.x),&(dif.y), &(dif.z)); + dif.x*=GetNx()>1?GetNx()-1:1; dif.y*=GetNy()>1?GetNy()-1:1; dif.z*=GetNz()>1?GetNz()-1:1; return res; } +}; +//----------------------------------------------------------------------------- +/// Structure for color ID +struct MGL_EXPORT mglColorID +{ + char id; + mglColor col; +}; +MGL_EXPORT extern mglColorID mglColorIds[31]; +MGL_EXPORT extern std::string mglGlobalMess; ///< Buffer for receiving global messages +//----------------------------------------------------------------------------- +#endif + +#ifdef MGL_SRC +#define _Da_(d) (*((const mglDataA *)(d))) +#define _DA_(a) ((const mglDataA *)*(a)) +#define _GR_ ((mglBase *)(*gr)) +//#define _D_(d) *((mglData *)*(d)) +#define _DM_(a) ((mglData *)*(a)) +#define _DT_ ((mglData *)*d) +#endif + +#endif diff --git a/include/mgl2/base.h b/include/mgl2/base.h index a455625..154640a 100644 --- a/include/mgl2/base.h +++ b/include/mgl2/base.h @@ -33,6 +33,12 @@ #else #define MGL_PUSH(a,v,m) a.push_back(v); #endif + +#if MGL_HAVE_PTHREAD +#define MGL_PUSHs(func,m) {pthread_mutex_lock(&m); func; pthread_mutex_unlock(&m);} +#else +#define MGL_PUSHs(func,m) {func;} +#endif //----------------------------------------------------------------------------- inline mreal mgl_d(mreal v,mreal v1,mreal v2) { return v2!=v1?(v-v1)/(v2-v1):NAN; } //----------------------------------------------------------------------------- @@ -44,55 +50,66 @@ mglPoint GetZ(HCDT z, int i, int j, int k=0); // NOTE memcpy is used --> no memory allocation in T template class mglStack { - T** dat; - size_t pb; ///< size of buffer (real size is 2^pb == 1L< &st) - { np=st.np; dat = (T**)malloc(np*sizeof(T*)); - pb=st.pb; m=n=0; reserve(st.n); - for(size_t i=0;i(m<(nb<>pb); - if(num>np) - { dat = (T**)realloc(dat, num*sizeof(T*)); np=num; } - for(size_t i=m;i>MGL_PB); + for(;nb>pb; return dat[d][i-(d<>pb; return dat[d][i-(d<>MGL_PB; return dat[d][i-(d<>MGL_PB; return dat[d][i-(d<=(m<>pb; - dat[d][n-(d<=(nb<>MGL_PB; dat[d][n-(d<=(nb<>MGL_PB; dat[d][n-(d< &operator=(const mglStack &st) { - pb=st.pb; clear(); reserve(st.n); - for(size_t i=0;i(const mglPrim &a,const mglPrim &b); /// Structure for light source struct MGL_EXPORT mglLight { - mglLight():n(false),a(0),b(0) {} - mglLight(const mglLight &aa) : n(aa.n),d(aa.d),r(aa.r),q(aa.q),p(aa.p),a(aa.a),b(aa.b),c(aa.c) {} + mglLight():a(0),b(0),n(false) {} + mglLight(const mglLight &aa) : d(aa.d),r(aa.r),q(aa.q),p(aa.p),c(aa.c),a(aa.a),b(aa.b),n(aa.n) {} + const mglLight &operator=(const mglLight &aa) + { memcpy(this,&aa,sizeof(mglLight)); return aa; } - bool n; ///< Availability of light sources mglPoint d; ///< Direction of light sources mglPoint r; ///< Position of light sources (NAN for infinity) mglPoint q; ///< Actual position of light sources (filled by LightScale() function) mglPoint p; ///< Actual direction of light sources (filled by LightScale() function) - mreal a; ///< Aperture of light sources - mreal b; ///< Brightness of light sources mglColor c; ///< Color of light sources + float a; ///< Aperture of light sources + float b; ///< Brightness of light sources + bool n; ///< Availability of light sources }; //----------------------------------------------------------------------------- /// Structure for inplot struct MGL_EXPORT mglBlock { - int id; ///< object id long n1,n2,n3,n4; ///< coordinates of corners {n1=x1,n2=x2,n3=y1,n4=y2} mglLight light[10]; ///< Light sources - mreal AmbBr; ///< Default ambient light brightness - mreal DifBr; ///< Default diffusive light brightness + float AmbBr; ///< Default ambient light brightness + float DifBr; ///< Default diffusive light brightness mglMatrix B; ///< Transformation matrix + int id; ///< object id - mglBlock():id(0),n1(0),n2(0),n3(0),n4(0),AmbBr(0.5),DifBr(0.5) {} + mglBlock():n1(0),n2(0),n3(0),n4(0),AmbBr(0.5),DifBr(0.5),id(0) {} mglBlock(const mglBlock &aa) { memcpy(this, &aa, sizeof(mglBlock)); } const mglBlock &operator=(const mglBlock &aa) { memcpy(this, &aa, sizeof(mglBlock)); return aa; } }; @@ -194,9 +214,9 @@ struct MGL_EXPORT mglText { std::wstring text; std::string stl; - mreal val; - mglText(const wchar_t *txt=L"", const char *fnt="", mreal v=0) : text(txt), stl(fnt), val(v) {} - mglText(const std::wstring &txt, mreal v=0): text(txt), val(v) {} + float val; + mglText(const wchar_t *txt=L"", const char *fnt="", float v=0) : text(txt), stl(fnt), val(v) {} + mglText(const std::wstring &txt, float v=0): text(txt), val(v) {} mglText(const mglText &aa) : text(aa.text),stl(aa.stl),val(aa.val) {} #if MGL_HAVE_RVAL mglText(mglText &&aa) : text(aa.text),stl(aa.stl),val(aa.val) {} @@ -207,52 +227,52 @@ struct MGL_EXPORT mglText /// Structure for internal point representation struct MGL_EXPORT mglPnt // NOTE: use float for reducing memory size { - union { float dat[16]; struct { + union { float dat[15]; struct { float x,y,z; // coordinates float u,v,w; // normales float r,g,b,a; // RGBA color float xx,yy,zz; // original coordinates - float c,t,ta; // index in color scheme + float c,ta; // index in color scheme }; }; - short sub; // subplot id and rotation information (later will be in subplot) - mglPnt(float X, float Y=0, float Z=0, float U=0, float V=0, float W=0, float R=0, float G=0, float B=0, float A=0):x(X),y(Y),z(Z),u(U),v(V),w(W),r(R),g(G),b(B),a(A),xx(X),yy(Y),zz(Z),c(0),t(0),ta(0),sub(0) {} - mglPnt():x(0),y(0),z(0),u(0),v(0),w(0),r(0),g(0),b(0),a(0),xx(0),yy(0),zz(0),c(0),t(0),ta(0),sub(0) {} - mglPnt(const mglPnt &aa) : sub(aa.sub) { memcpy(dat,aa.dat,16*sizeof(float)); } - inline const mglPnt&operator=(const mglPnt &aa) { sub=aa.sub; memcpy(dat,aa.dat,16*sizeof(float)); return aa; } + int sub; // subplot id and rotation information (later will be in subplot) + mglPnt(float X=0, float Y=0, float Z=0, float U=0, float V=0, float W=0, float R=0, float G=0, float B=0, float A=0, short s=0) :x(X),y(Y),z(Z),u(U),v(V),w(W),r(R),g(G),b(B),a(A),xx(X),yy(Y),zz(Z),c(0),ta(0),sub(s) {} + mglPnt(const mglPnt &aa) : sub(aa.sub) { memcpy(dat,aa.dat,15*sizeof(float)); } + inline const mglPnt&operator=(const mglPnt &aa) { sub=aa.sub; memcpy(dat,aa.dat,15*sizeof(float)); return aa; } + inline bool same(const mglPnt &p, mreal d) const { return fabs(x-p.x); -template class MGL_EXPORT mglStack; -template class MGL_EXPORT std::vector; -template class MGL_EXPORT std::vector; -template class MGL_EXPORT std::vector; -template class MGL_EXPORT std::vector; -template class MGL_EXPORT std::vector; -template class MGL_EXPORT std::vector; -template class MGL_EXPORT mglStack; +MGL_EXTERN template class MGL_EXPORT mglStack; +MGL_EXTERN template class MGL_EXPORT mglStack; +MGL_EXTERN template class MGL_EXPORT std::vector; +MGL_EXTERN template class MGL_EXPORT std::vector; +MGL_EXTERN template class MGL_EXPORT std::vector; +MGL_EXTERN template class MGL_EXPORT std::vector; +MGL_EXTERN template class MGL_EXPORT std::vector; +MGL_EXTERN template class MGL_EXPORT std::vector; +MGL_EXTERN template class MGL_EXPORT mglStack; #endif //----------------------------------------------------------------------------- /// Base class for canvas which handle all basic drawing @@ -335,6 +361,8 @@ public: std::vector Grp; ///< List of groups with names -- need for export mglStack Act; ///< Position of active points std::string PlotId; ///< Id of plot for saving filename (in GLUT window for example) + int BBoxX1, BBoxY1, BBoxX2, BBoxY2; ///< BBox region for exporting 2d graphics + std::vector UserGlf; ///< User-defined glyphs data mreal CDef; ///< Default (current) color in texture mreal AlphaDef; ///< Default value of alpha channel (transparency) @@ -420,6 +448,7 @@ public: /// Set default palette inline void SetPalette(const char *colors) { Txt[0].Set(mgl_have_color(colors)?colors:MGL_DEF_PAL,-1); } + inline void ResetPal() { CurrPal=0; } inline long GetNumPal(long id) const { return Txt[labs(id)/256].n; } /// Set default color scheme inline void SetDefScheme(const char *colors) @@ -428,11 +457,11 @@ public: /// Set number of mesh lines inline void SetMeshNum(int val) { MeshNum=val; } /// Set relative width of rectangles in Bars, Barh, BoxPlot - inline void SetBarWidth(mreal val) { BarWidth=val; } + inline void SetBarWidth(mreal val) { BarWidth=val>0?val:-BarWidth*val; } /// Set size of marks - inline void SetMarkSize(mreal val) { MarkSize=0.02*val; } + inline void SetMarkSize(mreal val) { MarkSize=val>0?0.02*val:-val*MarkSize; } /// Set size of arrows - inline void SetArrowSize(mreal val) { ArrowSize=0.03*val; } + inline void SetArrowSize(mreal val) { ArrowSize=val>0?0.03*val:-val*ArrowSize; } /// Get unscaled arrow size inline mreal GetArrowSize() const { return ArrowSize/0.03; } @@ -472,11 +501,13 @@ public: virtual mreal GetRatio() const MGL_FUNC_CONST; virtual int GetWidth() const MGL_FUNC_CONST; virtual int GetHeight() const MGL_FUNC_CONST; + /// Add user-defined glyph + void DefineGlyph(HCDT x, HCDT y, unsigned char id=0); /// Set to use or not text rotation inline void SetRotatedText(bool val) { set(val,MGL_ENABLE_RTEXT); } /// Set default font style and color - void SetFontDef(const char *font); + inline void SetFontDef(const char *font){ mgl_strncpy(FontDef, font, 31); } /// Set to use or not text rotation inline void SetTickRotate(bool val) { set(val,MGL_TICKS_ROTATE); } /// Set to use or not text rotation @@ -498,15 +529,33 @@ public: inline long AddPnt(mglPoint p, mreal c=-1, mglPoint n=mglPoint(NAN), mreal a=-1, int scl=1) { return AddPnt(&B,p,c,n,a,scl); } long AddPnt(const mglMatrix *M, mglPoint p, mreal c=-1, mglPoint n=mglPoint(NAN), mreal a=-1, int scl=1); + bool AddPntQ(mglPnt &q, const mglMatrix *M, mglPoint p, mreal c=-1, mglPoint n=mglPoint(NAN), mreal a=-1, int scl=1); + inline bool AddPntQ(mglPnt &q, mglPoint p, mreal c=-1, mglPoint n=mglPoint(NAN), mreal a=-1, int scl=1) + { return AddPntQ(q,&B,p,c,n,a,scl); } + inline bool AddPntQ(long id, const mglMatrix *M, mglPoint p, mreal c=-1, mglPoint n=mglPoint(NAN), mreal a=-1, int scl=1) + { return AddPntQ(Pnt[id],M,p,c,n,a,scl); } + inline bool AddPntQ(long id, mglPoint p, mreal c=-1, mglPoint n=mglPoint(NAN), mreal a=-1, int scl=1) + { return AddPntQ(Pnt[id],&B,p,c,n,a,scl); } + inline void SetPntOff(size_t id) { Pnt[id].x=NAN; } + long AllocPnts(size_t num); + long PushPnts(size_t num, const mglPnt *qq); long CopyNtoC(long k, mreal c); + bool CopyNtoC(mglPnt &q, long k, mreal c); + inline bool CopyNtoC(long id, long k, mreal c) + { return (id>=0)?CopyNtoC(Pnt[id],k,c):false; } long CopyProj(long from, mglPoint p, mglPoint n, short sub=0); + bool CopyProj(mglPnt &q, long from, mglPoint p, mglPoint n, short sub=0); + void CopyProj(long id, long from, mglPoint p, mglPoint n, short sub=0) + { if(id>=0) CopyProj(Pnt[id],from,p,n,sub); } void SetRGBA(long k, const mglColor &c) - { mglPnt &p=Pnt[k]; p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a; } - virtual void Reserve(long n); ///< Allocate n-cells for Pnt and return current position + { if(k>=0) {mglPnt &p=Pnt[k]; p.r = c.r; p.g = c.g; p.b = c.b; p.a = c.a;} } + virtual void Reserve(long n); ///< Allocate n-cells for Pnt and return current position /// Set to reduce accuracy of points (to reduce size of output files) inline void SetReduceAcc(bool val) { set(val, MGL_REDUCEACC); } /// Add glyph of current font to the Glf and return its position long AddGlyph(int s, long j); + /// Add glyph to the Glf and return its position + long AddGlyph(unsigned char id); /// Add active point as k-th element of Pnt void AddActive(long k,int n=0); /// Clear unused points and primitives @@ -526,6 +575,13 @@ public: inline long GetGlfNum() const { return Glf.size(); } inline const mglPnt &GetPnt(long i) const { return Pnt[i]; } inline long GetPntNum() const { return Pnt.size(); } + inline bool SamePnt(long i, long j) const + { + if(i<0 || j<0) return true; + const mglPnt &p=Pnt[i], &q=Pnt[j]; + return mgl_isnan(p.x) || mgl_isnan(q.x) || (p.x==q.x && p.y==q.y); + } + inline bool ValidPnt(size_t i) { return mgl_isnum(Pnt[i].x); } // inline mglPrim &GetPrm(long i) { return Prm[i]; } inline mglPrim &GetPrm(long i, bool sort=true) { return (sort && PrmInd) ? Prm[PrmInd[i]]:Prm[i]; } @@ -539,6 +595,9 @@ public: /// Scale coordinates and cut off some points virtual bool ScalePoint(const mglMatrix *M, mglPoint &p, mglPoint &n, bool use_nan=true) const; + inline const mglBlock &GetSub(size_t i) const { return Sub[i]; } + inline const mglBlock &GetSub() const { return Sub.back(); } + virtual mreal GetOrgX(char dir, bool inv=false) const=0; ///< Get Org.x (parse NAN value) virtual mreal GetOrgY(char dir, bool inv=false) const=0; ///< Get Org.y (parse NAN value) virtual mreal GetOrgZ(char dir, bool inv=false) const=0; ///< Get Org.z (parse NAN value) @@ -566,14 +625,21 @@ public: virtual void line_plot(long p1, long p2)=0; virtual void trig_plot(long p1, long p2, long p3)=0; virtual void quad_plot(long p1, long p2, long p3, long p4)=0; + virtual void smbl_plot(long p1, char id, double size)=0; + void curve_plot(size_t n, size_t kq, size_t step=1); virtual void Glyph(mreal x, mreal y, mreal f, int style, long icode, mreal col)=0; virtual float GetGlyphPhi(const mglPnt &q, float phi)=0; virtual mreal text_plot(long p,const wchar_t *text,const char *fnt,mreal size=-1,mreal sh=0,mreal col=-('k'),bool rot=true)=0; void vect_plot(long p1, long p2, mreal s=1); + + // check if visible + virtual bool trig_vis(const mglPnt &p1, const mglPnt &p2, const mglPnt &p3) const =0; + virtual bool quad_vis(const mglPnt &p1, const mglPnt &p2, const mglPnt &p3, const mglPnt &p4) const =0; + inline mreal mark_size() { return MarkSize*font_factor; } // inline char last_color() { return last_style[1]; } inline const char *last_line() { return last_style; } - int PrmCmp(long i, long j) const MGL_FUNC_PURE; // compare 2 primitives with indexes i,j + int PrmCmp(size_t i, size_t j) const MGL_FUNC_PURE; // compare 2 primitives with indexes i,j /// Check if plot termination is asked bool NeedStop() { if(event_cb) event_cb(event_par); return Stop; } /// Ask to stop drawing @@ -594,7 +660,7 @@ protected: mglPoint FMax; ///< Actual upper edge after transformation formulas. mglPoint Org; ///< Center of axis cross section. int WarnCode; ///< Warning code - long *PrmInd; ///< Indexes of sorted primitives + size_t *PrmInd; ///< Indexes of sorted primitives mglStack Pnt; ///< Internal points mglStack Prm; ///< Primitives (lines, triangles and so on) -- need for export std::vector Sub; ///< InPlot regions @@ -613,8 +679,8 @@ protected: mreal pPos; ///< Current position in pen mask mreal PenWidth; ///< Pen width for further line plotting (must be >0 !!!) // long numT; ///< Number of textures - mreal AmbBr; ///< Default ambient light brightness // TODO move to mglBlock - mreal DifBr; ///< Default diffusive light brightness // TODO move to mglBlock + mreal AmbBr; ///< Default ambient light brightness + mreal DifBr; ///< Default diffusive light brightness mreal persp; ///< Original value for perspective mglMatrix Bp; ///< Transformation matrix for View() and Zoom() @@ -626,16 +692,16 @@ protected: char FontDef[32]; ///< Font specification (see mglGraph::Puts). Default is Roman with align at center. int Quality; ///< Quality of plot (0x0-pure, 0x1-fast; 0x2-fine; 0x4 - low memory) - mglFormula *fx; ///< Transformation formula for x direction. - mglFormula *fy; ///< Transformation formula for y direction. - mglFormula *fz; ///< Transformation formula for z direction. - mglFormula *fa; ///< Transformation formula for coloring. - mglFormula *fc; ///< Cutting off condition (formula). + HMEX fx; ///< Transformation formula for x direction. + HMEX fy; ///< Transformation formula for y direction. + HMEX fz; ///< Transformation formula for z direction. + HMEX fa; ///< Transformation formula for coloring. + HMEX fc; ///< Cutting off condition (formula). long CurrPal; ///< Current palette index mreal MarkSize; ///< The size of marks for 1D plots. mreal ArrowSize; ///< The size of arrows. - char last_style[64];///< Last pen style + char last_style[64];///< Last pen style TODO: replace by std::string mreal font_factor; ///< Font scaling factor long dr_x, dr_y, dr_p; ///< default drawing region for quality&4 mode diff --git a/include/mgl2/base_cf.h b/include/mgl2/base_cf.h index 9bcb771..77a6dbc 100644 --- a/include/mgl2/base_cf.h +++ b/include/mgl2/base_cf.h @@ -213,6 +213,9 @@ void MGL_EXPORT mgl_set_font_def_(uintptr_t *gr, const char *fnt, int); /// Set to use or not text rotation void MGL_EXPORT mgl_set_rotated_text(HMGL gr, int enable); void MGL_EXPORT mgl_set_rotated_text_(uintptr_t *gr, int *enable); +/// Set to scale text in relative subplots too +void MGL_EXPORT mgl_set_scale_text(HMGL gr, int enable); +void MGL_EXPORT mgl_set_scale_text_(uintptr_t *gr, int *enable); /// Load font from file void MGL_EXPORT mgl_load_font(HMGL gr, const char *name, const char *path); void MGL_EXPORT mgl_load_font_(uintptr_t *gr, char *name, char *path, int l, int n); @@ -222,6 +225,9 @@ void MGL_EXPORT mgl_copy_font_(uintptr_t *gr, uintptr_t *gr_from); /// Restore font (load default font for new HMGL objects) void MGL_EXPORT mgl_restore_font(HMGL gr); void MGL_EXPORT mgl_restore_font_(uintptr_t *gr); +/// Add user-defined glyph for symbol and set its optional id +void MGL_EXPORT mgl_define_symbol(HMGL gr, char id, HCDT x, HCDT y); +void MGL_EXPORT mgl_define_symbol_(uintptr_t *gr, char *id, uintptr_t *x, uintptr_t *y,int); #ifdef __cplusplus } diff --git a/include/mgl2/canvas.h b/include/mgl2/canvas.h index d8c1db6..10e695e 100644 --- a/include/mgl2/canvas.h +++ b/include/mgl2/canvas.h @@ -26,15 +26,18 @@ struct GifFileType; /// Structure for drawing axis and ticks struct MGL_EXPORT mglAxis { - mglAxis() : dv(0),ds(0),d(0),ns(0), v0(0),v1(0),v2(0),o(NAN), f(0), ch(0), pos('t'),sh(0),inv(false) {} - mglAxis(const mglAxis &aa) : dv(aa.dv),ds(aa.ds),d(aa.d),ns(aa.ns), t(aa.t),fact(aa.fact),stl(aa.stl), dir(aa.dir),a(aa.a),b(aa.b),org(aa.org), v0(aa.v0),v1(aa.v1),v2(aa.v2),o(aa.o), f(aa.f),txt(aa.txt), ch(aa.ch), pos(aa.pos),sh(aa.sh),inv(aa.inv) {} + mglAxis() : dv(0),ds(0),d(0),ns(0), v0(0),v1(0),v2(0),o(NAN), f(0), ch(0), pos('t'),sh(0),inv(false),angl(NAN) {} + mglAxis(const mglAxis &aa) : dv(aa.dv),ds(aa.ds),d(aa.d),ns(aa.ns), t(aa.t),fact(aa.fact),stl(aa.stl), dir(aa.dir),a(aa.a),b(aa.b),org(aa.org), v0(aa.v0),v1(aa.v1),v2(aa.v2),o(aa.o), f(aa.f),txt(aa.txt), ch(aa.ch), pos(aa.pos),sh(aa.sh),inv(aa.inv),angl(aa.angl) {} #if MGL_HAVE_RVAL - mglAxis(mglAxis &&aa) : dv(aa.dv),ds(aa.ds),d(aa.d),ns(aa.ns), t(aa.t),fact(aa.fact),stl(aa.stl), dir(aa.dir),a(aa.a),b(aa.b),org(aa.org), v0(aa.v0),v1(aa.v1),v2(aa.v2),o(aa.o), f(aa.f),txt(aa.txt), ch(aa.ch), pos(aa.pos),sh(aa.sh),inv(aa.inv) {} + mglAxis(mglAxis &&aa) : dv(aa.dv),ds(aa.ds),d(aa.d),ns(aa.ns), t(aa.t),fact(aa.fact),stl(aa.stl), dir(aa.dir),a(aa.a),b(aa.b),org(aa.org), v0(aa.v0),v1(aa.v1),v2(aa.v2),o(aa.o), f(aa.f),txt(aa.txt), ch(aa.ch), pos(aa.pos),sh(aa.sh),inv(aa.inv),angl(aa.angl) {} #endif - inline void AddLabel(const wchar_t *lbl, mreal v) - { if(mgl_isfin(v)) txt.push_back(mglText(lbl,"",v)); } + + const mglAxis &operator=(const mglAxis &aa) + { dv=aa.dv; ds=aa.ds; d=aa.d; ns=aa.ns; t=aa.t; fact=aa.fact; stl=aa.stl; + dir=aa.dir; a=aa.a; b=aa.b; org=aa.org; v0=aa.v0; v1=aa.v1; v2=aa.v2; o=aa.o; + f=aa.f; txt=aa.txt; ch=aa.ch; pos=aa.pos; sh=aa.sh; inv=aa.inv; return aa; } inline void AddLabel(const std::wstring &lbl, mreal v) - { if(mgl_isfin(v)) txt.push_back(mglText(lbl,v)); } + { if(mgl_isfin(v)) txt.push_back(mglText(L' '+lbl+L' ',v)); } inline void Clear() { dv=ds=d=v0=v1=v2=sh=0; o=NAN; ns=f=0; pos = 't'; inv=false; fact.clear(); stl.clear(); t.clear(); txt.clear(); } @@ -65,11 +68,14 @@ class mglCanvas; /// Structure for drawing region struct MGL_EXPORT mglDrawReg { - mglDrawReg() {} + mglDrawReg() { memset(this,0,sizeof(mglDrawReg)); } mglDrawReg(const mglDrawReg &aa) : PDef(aa.PDef),angle(aa.angle),ObjId(aa.ObjId),PenWidth(aa.PenWidth),pPos(aa.pPos) ,x1(aa.x1),x2(aa.x2),y1(aa.y1),y2(aa.y2) {} #if MGL_HAVE_RVAL mglDrawReg(mglDrawReg &&aa) : PDef(aa.PDef),angle(aa.angle),ObjId(aa.ObjId),PenWidth(aa.PenWidth),pPos(aa.pPos) ,x1(aa.x1),x2(aa.x2),y1(aa.y1),y2(aa.y2) {} #endif + inline void copy(const mglPrim &p) + { PDef = p.n3; pPos = p.s; ObjId = p.id; PenWidth=p.w; angle = p.angl; + if(p.type==2 || p.type==3) PDef = p.m; } inline const mglDrawReg &operator=(const mglDrawReg &aa) { memcpy(this,&aa,sizeof(mglDrawReg)); return aa; } union @@ -102,7 +108,7 @@ struct MGL_EXPORT mglDrawDat std::vector Txt; ///< Pointer to textures }; #if defined(_MSC_VER) -template class MGL_EXPORT std::vector; +MGL_EXTERN template class MGL_EXPORT std::vector; #endif //----------------------------------------------------------------------------- union mglRGBA { uint32_t c; unsigned char r[4]; }; @@ -139,7 +145,7 @@ using mglBase::Light; /// Get PlotFactor inline mreal GetPlotFactor() { return B.pf; } /// Pop transformation matrix from stack - inline void Pop() { B = stack.back(); stack.pop_back(); } + void Pop(); /// Clear up the frame virtual void Clf(mglColor back=NC); virtual void Clf(const char *col); @@ -167,6 +173,12 @@ using mglBase::Light; /// Set perspective (in range [0,1)) for plot. Set to zero for switching off. Return the current perspective. void Perspective(mreal a, bool req=true) { if(req) persp = Bp.pf = a; else Bp.pf = persp?persp:fabs(a); } + /// Save parameters of current inplot + inline void SaveInPlot() + { sB=B; sW=inW, sH=inH, sZ=ZMin, sX=inX, sY=inY, sFF=font_factor; } + /// Use saved parameters as current inplot + inline void LoadInPlot() + { B=sB; inW=sW, inH=sH, ZMin=sZ, inX=sX, inY=sY, font_factor=sFF; } /// Set size of frame in pixels. Normally this function is called internaly. virtual void SetSize(int w,int h,bool clf=true); @@ -186,6 +198,9 @@ using mglBase::Light; int GetHeight() const { return Height; } /// Combine plots from 2 canvases. Result will be saved into this. void Combine(const mglCanvas *gr); + /// Set boundary box for export graphics into 2D file formats + void SetBBox(int x1=0, int y1=0, int x2=-1, int y2=-1) + { BBoxX1=x1; BBoxY1=y1; BBoxX2=x2; BBoxY2=y2; } /// Rasterize current plot and set it as background image void Rasterize(); @@ -206,7 +221,7 @@ using mglBase::Light; inline void SetObjId(long id) { ObjId = id; } /// Get object id inline int GetObjId(long xs,long ys) const - { register long i=xs+Width*ys; return (i>=0 && i=0 && i stack; ///< stack for transformation matrices @@ -462,7 +495,7 @@ private: void tick_draw(mglPoint o, mglPoint d1, mglPoint d2, int f); mreal FindOptOrg(char dir, int ind) const MGL_FUNC_PURE; /// Transform mreal color and alpha to bits format - unsigned char* col2int(const mglPnt &p, unsigned char *r, int obj_id) const; + void col2int(const mglPnt &p, unsigned char *r, int obj_id) const; /// Combine colors in 2 plane. void combine(unsigned char *c1, const unsigned char *c2) const; /// Fast drawing of line between 2 points @@ -475,11 +508,6 @@ private: /// Set coordinate and add the point, return its id long setPp(mglPnt &q, const mglPoint &p); - // functions for glyph drawing - void glyph_fill(const mglMatrix *M, const mglPnt &p, mreal f, const mglGlyph &g, const mglDrawReg *d); - void glyph_wire(const mglMatrix *M, const mglPnt &p, mreal f, const mglGlyph &g, const mglDrawReg *d); - void glyph_line(const mglMatrix *M, const mglPnt &p, mreal f, bool solid, const mglDrawReg *d); - // fill pixel for given primitive void mark_pix(long i,long j,const mglPnt &p, char type, mreal size, mglDrawReg *d); void arrow_pix(long i,long j,const mglPnt &p1, const mglPnt &p2, char st, mreal size, const mglDrawReg *d); @@ -504,4 +532,11 @@ struct mglThreadG /// Start several thread for the task void mglStartThread(void (mglCanvas::*func)(long i, long n), mglCanvas *gr, long n); //----------------------------------------------------------------------------- +inline mreal get_persp(float pf, float z, float Depth) +//{ return (1-pf)/(1-pf*z/Depth); } +{ return (1-pf/1.37)/(1-pf*z/Depth); } +inline mreal get_pfact(float pf, float Depth) +//{ return pf/(1-pf)/Depth; } +{ return pf/(1-pf/1.37)/Depth; } +//----------------------------------------------------------------------------- #endif diff --git a/include/mgl2/canvas_cf.h b/include/mgl2/canvas_cf.h index 91fddea..5892897 100644 --- a/include/mgl2/canvas_cf.h +++ b/include/mgl2/canvas_cf.h @@ -52,6 +52,11 @@ void MGL_EXPORT mgl_finish_(uintptr_t *gr); /// Force preparing the image and save result into background one. void MGL_EXPORT mgl_rasterize(HMGL gr); void MGL_EXPORT mgl_rasterize_(uintptr_t *gr); +/// Set boundary box for export graphics into 2D file formats. +/** If x2<0 (y2<0) then full width (height) will be used. + * If x1<0 or y1<0 or x1>=x2|Width or y1>=y2|Height then cropping will be disabled. */ +void MGL_EXPORT mgl_set_bbox(HMGL gr, int x1, int y1, int x2, int y2); +void MGL_EXPORT mgl_set_bbox_(uintptr_t *gr, int *x1, int *y1, int *x2, int *y2); /// Set the size of semi-transparent area around lines, marks, glyphs, ... Default is 1. void MGL_EXPORT mgl_pen_delta(HMGL gr, double d); @@ -467,6 +472,15 @@ void MGL_EXPORT mgl_subplot_d_(uintptr_t *gr, int *nx,int *ny,int *m, mreal *dx, * '#' for using whole region. */ void MGL_EXPORT mgl_multiplot(HMGL gr, int nx,int ny,int m,int dx,int dy,const char *style); void MGL_EXPORT mgl_multiplot_(uintptr_t *gr, int *nx,int *ny,int *m,int *dx,int *dy, const char *s,int); +/// Put further plotting in rectangle of dx*dy cells starting from m-th cell of nx*ny grid of the image and shift it by distance {sx,sy}.. +/** String \a style may contain: + * '<' for reserving space at left + * '>' for reserving space at right + * '^' for reserving space at top + * '_' for reserving space at bottom + * '#' for using whole region. */ +void MGL_EXPORT mgl_multiplot_d(HMGL gr, int nx,int ny,int m,int dx,int dy,const char *style,double sx,double sy); +void MGL_EXPORT mgl_multiplot_d_(uintptr_t *gr, int *nx,int *ny,int *m,int *dx,int *dy, const char *s, mreal *sx, mreal *sy,int); /// Put further plotting in a region [x1,x2]*[y1,y2] of the image (x1,x2,y1,y2 in range [0, 1]). void MGL_EXPORT mgl_inplot(HMGL gr, double x1,double x2,double y1,double y2); void MGL_EXPORT mgl_inplot_(uintptr_t *gr, mreal *x1, mreal *x2, mreal *y1, mreal *y2); @@ -527,8 +541,12 @@ void MGL_EXPORT mgl_set_click_func(HMGL gr, void (*func)(void *p)); void MGL_EXPORT mgl_wnd_set_mutex(HMGL gr, pthread_mutex_t *mutex); #endif +/// Make custom dialog for parameters ids of element properties defined by args +void MGL_EXPORT mgl_wnd_make_dialog(HMGL gr, const char *ids, char const * const *args, const char *title); /// Set callback functions for drawing and data reloading void MGL_EXPORT mgl_wnd_set_func(HMGL gr, int (*draw)(HMGL gr, void *p), void *par, void (*reload)(void *p)); +/// Set callback functions for setting properties +void MGL_EXPORT mgl_wnd_set_prop(HMGL gr, void (*prop)(char id, const char *val, void *p), void *par); /// Set delay for animation in seconds void MGL_EXPORT mgl_wnd_set_delay(HMGL gr, double dt); void MGL_EXPORT mgl_wnd_set_delay_(uintptr_t *gr, mreal *dt); @@ -607,6 +625,14 @@ uintptr_t MGL_EXPORT mgl_parser_get_var_(uintptr_t* p, unsigned long *id); long MGL_EXPORT mgl_parser_num_var(HMPR p); long MGL_EXPORT mgl_parser_num_var_(uintptr_t* p); +/// Get constant with given id +/// NOTE !!! You must not delete obtained data arrays !!! +MGL_EXPORT mglNum *mgl_parser_get_const(HMPR p, unsigned long id); +uintptr_t MGL_EXPORT mgl_parser_get_const_(uintptr_t* p, unsigned long *id); +/// Get number of constants +long MGL_EXPORT mgl_parser_num_const(HMPR p); +long MGL_EXPORT mgl_parser_num_const_(uintptr_t* p); + /// Delete variable with name void MGL_EXPORT mgl_parser_del_var(HMPR p, const char *name); void MGL_EXPORT mgl_parser_del_var_(uintptr_t* p, const char *name, int); @@ -624,6 +650,10 @@ void MGL_EXPORT mgl_rk_step(HMPR pr, const char *eqs, const char *vars, mreal dt void MGL_EXPORT mgl_rk_step_w(HMPR pr, const wchar_t *eqs, const wchar_t *vars, mreal dt); void MGL_EXPORT mgl_rk_step_(uintptr_t *p, const char *eqs, const char *vars, double *dt, int,int); +// Open all data arrays from HDF file and assign it as variables of parser p +void MGL_EXPORT mgl_parser_openhdf(HMPR p, const char *fname); +void MGL_EXPORT mgl_parser_openhdf_(uintptr_t *p, const char *fname,int l); + /// Parse and draw single line of the MGL script int MGL_EXPORT mgl_parse_line(HMGL gr, HMPR p, const char *str, int pos); int MGL_EXPORT mgl_parse_line_(uintptr_t* gr, uintptr_t* p, const char *str, int *pos, int); @@ -653,6 +683,10 @@ void MGL_EXPORT mgl_parser_stop_(uintptr_t* p); /// Set variant of argument(s) separated by '?' to be used void MGL_EXPORT mgl_parser_variant(HMPR p, int var); void MGL_EXPORT mgl_parser_variant_(uintptr_t* p, int *var); +/// Set starting object ID +void MGL_EXPORT mgl_parser_start_id(HMPR p, int id); +void MGL_EXPORT mgl_parser_start_id_(uintptr_t* p, int *id); + /// Return type of command: 0 - not found, 1 - data plot, 2 - other plot, /// 3 - setup, 4 - data handle, 5 - data create, 6 - subplot, 7 - program @@ -664,7 +698,7 @@ int MGL_EXPORT mgl_parser_cmd_type_(uintptr_t* p, const char *name, int); MGL_EXPORT const char *mgl_parser_cmd_desc(HMPR pr, const char *name); /// Return string of command format (command name and its argument[s]) MGL_EXPORT const char *mgl_parser_cmd_frmt(HMPR pr, const char *name); -/// Get name of command with nmber n +/// Get name of command with number n MGL_EXPORT const char *mgl_parser_cmd_name(HMPR pr, long id); /// Get number of defined commands long MGL_EXPORT mgl_parser_cmd_num(HMPR pr); diff --git a/include/mgl2/canvas_wnd.h b/include/mgl2/canvas_wnd.h index 19091ed..4c330f3 100644 --- a/include/mgl2/canvas_wnd.h +++ b/include/mgl2/canvas_wnd.h @@ -53,11 +53,11 @@ public: virtual void ToggleAlpha()=0; ///< Switch on/off transparency (do not overwrite user settings) virtual void ToggleLight()=0; ///< Switch on/off lighting (do not overwrite user settings) - virtual void ToggleZoom()=0; ///< Switch on/off zooming by mouse + virtual void ToggleZoom()=0; ///< Switch on/off zooming by mouse virtual void ToggleRotate()=0; ///< Switch on/off rotation by mouse virtual void ToggleNo()=0; ///< Switch off all zooming and rotation - virtual void Update()=0; ///< Update picture by calling user drawing function - virtual void Adjust()=0; ///< Adjust size of bitmap to window size + virtual void Update()=0; ///< Update picture by calling user drawing function + virtual void Adjust()=0; ///< Adjust size of bitmap to window size virtual void GotoFrame(int d)=0;///< Show arbitrary frame (use relative step) virtual void NextFrame() {GotoFrame(+1);} ///< Show next frame (if one) virtual void PrevFrame() {GotoFrame(-1);} ///< Show previous frame (if one) @@ -68,6 +68,13 @@ public: const char *title, void *par=NULL, void (*reload)(void *p)=NULL, bool maximize=false)=0; void SetDrawFunc(int (*draw)(mglBase *gr, void *p), void *par=NULL, void (*reload)(void *p)=NULL); + /// Set callback function for properties setup + void SetPropFunc(void (*prop)(char id, const char *val, void *p), void *par=NULL) + { PropFunc = prop; PropPar = par; } + inline void SetParam(char id, const char *val) ///< Set parameter (usually from custom dialog) + { if(PropFunc) { PropFunc(id,val,PropPar); Update(); } } + ///< Make custom dialog + virtual void MakeDialog(const char *ids, char const * const *args, const char *title="")=0; private: int CurFig; ///< Current figure in the list. @@ -78,6 +85,9 @@ private: void *FuncPar; ///< Parameters for drawing function mglCanvas::DrawFunc. /// Drawing function for window procedure. It should return the number of frames. int (*DrawFunc)(mglBase *gr, void *par); + void *PropPar; ///< Parameters for prop_func(). + /// Function for setting properties. + void (*PropFunc)(char id, const char *val, void *par); }; //----------------------------------------------------------------------------- #endif diff --git a/include/mgl2/cont.h b/include/mgl2/cont.h index bd3b91c..6f52224 100644 --- a/include/mgl2/cont.h +++ b/include/mgl2/cont.h @@ -123,6 +123,20 @@ void MGL_EXPORT mgl_contv_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr void MGL_EXPORT mgl_contv(HMGL gr, HCDT z, const char *sch, const char *opt); void MGL_EXPORT mgl_contv_(uintptr_t *gr, uintptr_t *z, const char *sch, const char *opt,int,int); + +/// Draw contour lines on parametric surface at manual levels for 2d data specified parametrically +/** Style ‘f’ to draw solid contours. + * Style ‘t’/‘T’ draw contour labels below/above contours. */ +void MGL_EXPORT mgl_contp_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt); +void MGL_EXPORT mgl_contp_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, const char *opt,int,int); +/// Draw contour lines on parametric surface for 2d data specified parametrically +/** Style ‘f’ to draw solid contours. + * Style ‘t’/‘T’ draw contour labels below/above contours. + * Option "value" set the number of contour levels (default is 7). */ +void MGL_EXPORT mgl_contp(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt); +void MGL_EXPORT mgl_contp_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, const char *opt,int,int); + + /// Draw axial-symmetric isosurfaces at manual levels for 2d data specified parametrically /** String \a sch may contain: * ‘#’ for wired plot; diff --git a/include/mgl2/data.h b/include/mgl2/data.h index 462ec83..06658ff 100644 --- a/include/mgl2/data.h +++ b/include/mgl2/data.h @@ -28,7 +28,6 @@ mreal MGL_EXPORT mglLinear(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mreal z); mreal MGL_EXPORT mglSpline3(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mreal z,mreal *dx=0, mreal *dy=0, mreal *dz=0); mreal MGL_EXPORT mglSpline3s(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mreal z); -std::string MGL_EXPORT mgl_data_to_string(HCDT d, long ns); //----------------------------------------------------------------------------- /// Class for working with data array class MGL_EXPORT mglData : public mglDataA @@ -39,14 +38,13 @@ using mglDataA::Momentum; long ny; ///< number of points in 2nd dimensions ('y' dimension) long nz; ///< number of points in 3d dimensions ('z' dimension) mreal *a; ///< data array - std::string id; ///< column (or slice) names bool link; ///< use external data (i.e. don't free it) /// Initiate by other mglData variable mglData(const mglData &d) { a=0; mgl_data_set(this,&d); } // NOTE: must be constructor for mglData& to exclude copy one #if MGL_HAVE_RVAL - mglData(mglData &&d):nx(d.nx),ny(d.ny),nz(d.nz),a(d.a),id(d.id),link(d.link) - { s=d.s; temp=d.temp; func=d.func; o=d.o; d.a=0; d.func=0; } + mglData(mglData &&d):nx(d.nx),ny(d.ny),nz(d.nz),a(d.a),link(d.link) + { s=d.s; temp=d.temp; func=d.func; o=d.o; id=d.id; d.a=0; d.func=0; } #endif mglData(const mglDataA *d) { a=0; if(d) mgl_data_set(this, d); else mgl_data_create(this,1,1,1); } @@ -143,6 +141,7 @@ using mglDataA::Momentum; mgl_data_create(this,n,1,1); va_list vl; va_start(vl,n); for(long i=0;i0? (i0? (i0? (j0? (j0? (k0? (k= 7 and F.nx >= 2 and F.nz=A.ny. * F[0,i,j] denote function id. F[1,i,j] give function weight, F(2:5,i,j) provide function parameters. @@ -598,7 +635,7 @@ public: #endif }; //----------------------------------------------------------------------------- -/// Class which present variable as data array +/// Class which present equidistantly distributed data class MGL_EXPORT mglDataV : public mglDataA { long nx; ///< number of points in 1st dimensions ('x' dimension) @@ -656,7 +693,7 @@ public: mreal value(mreal x,mreal y=0,mreal z=0) const { return a0+di*x+dj*y+dk*z; } mreal v(long i,long j=0,long k=0) const { return a0+di*i+dj*j+dk*k; } mreal vthr(long ii) const - { register long i=ii%nx, j=(ii/nx)%ny, k=ii/(nx*ny); return a0+di*i+dj*j+dk*k; } + { long i=ii%nx, j=(ii/nx)%ny, k=ii/(nx*ny); return a0+di*i+dj*j+dk*k; } // add for speeding up !!! mreal dvx(long ,long =0,long =0) const { return di; } mreal dvy(long ,long =0,long =0) const { return dj; } @@ -717,7 +754,7 @@ public: mreal v(long i,long j=0,long k=0) const { return di*(i0? (i= 7 and F.nx >= 2 and F.nz=A.ny. @@ -227,6 +254,11 @@ enum { HMDT MGL_EXPORT mgl_data_flame_2d(HCDT A, HCDT F, long n, long skip); uintptr_t MGL_EXPORT mgl_data_flame_2d_(uintptr_t *A, uintptr_t *F, long *n, long *skip); +/// Get curves, separated by NAN, for maximal values of array d as function of x coordinate. +/** Noises below lvl amplitude are ignored. + * Parameter dy \in [0,ny] set the "attraction" distance of points to curve. */ +HMDT MGL_EXPORT mgl_data_detect(HCDT d, mreal lvl, mreal dj, mreal di, mreal min_len); +uintptr_t MGL_EXPORT mgl_data_detect_(uintptr_t *d, mreal *lvl, mreal *dj, mreal *di, mreal *min_len); /// Get array as solution of tridiagonal matrix solution a[i]*x[i-1]+b[i]*x[i]+c[i]*x[i+1]=d[i] /** String \a how may contain: @@ -314,6 +346,12 @@ void MGL_EXPORT mgl_data_mirror_(uintptr_t *dat, const char *dir,int); /// Sort rows (or slices) by values of specified column void MGL_EXPORT mgl_data_sort(HMDT dat, long idx, long idy); void MGL_EXPORT mgl_data_sort_(uintptr_t *dat, int *idx, int *idy); +/// Return dilated array of 0 or 1 for data values larger val +void MGL_EXPORT mgl_data_dilate(HMDT dat, mreal val, long step); +void MGL_EXPORT mgl_data_dilate_(uintptr_t *dat, mreal *val, int *step); +/// Return eroded array of 0 or 1 for data values larger val +void MGL_EXPORT mgl_data_erode(HMDT dat, mreal val, long step); +void MGL_EXPORT mgl_data_erode_(uintptr_t *dat, mreal *val, int *step); /// Apply Hankel transform void MGL_EXPORT mgl_data_hankel(HMDT dat, const char *dir); @@ -324,7 +362,12 @@ void MGL_EXPORT mgl_data_sinfft_(uintptr_t *dat, const char *dir,int); /// Apply Cos-Fourier transform void MGL_EXPORT mgl_data_cosfft(HMDT dat, const char *dir); void MGL_EXPORT mgl_data_cosfft_(uintptr_t *dat, const char *dir,int); -/// Fill data by 'x'/'k' samples for Hankel ('h') or Fourier ('f') transform +/// Fill data by coordinates/momenta samples for Hankel ('h') or Fourier ('f') transform +/** Parameter \a how may contain: + * ‘x‘,‘y‘,‘z‘ for direction (only one will be used), + * ‘k‘ for momenta samples, + * ‘h‘ for Hankel samples, + * ‘f‘ for Cartesian/Fourier samples (default). */ void MGL_EXPORT mgl_data_fill_sample(HMDT dat, const char *how); void MGL_EXPORT mgl_data_fill_sample_(uintptr_t *dat, const char *how,int); /// Find correlation between 2 data arrays @@ -403,6 +446,9 @@ void MGL_EXPORT mgl_data_sew_(uintptr_t *dat, const char *dirs, mreal *da, int); /// Crop the data void MGL_EXPORT mgl_data_crop(HMDT dat, long n1, long n2, char dir); void MGL_EXPORT mgl_data_crop_(uintptr_t *dat, int *n1, int *n2, const char *dir,int); +/// Crop the data to be most optimal for FFT (i.e. to closest value of 2^n*3^m*5^l) +void MGL_EXPORT mgl_data_crop_opt(HMDT dat, const char *how); +void MGL_EXPORT mgl_data_crop_opt_(uintptr_t *dat, const char *how,int); /// Remove rows with duplicate values in column id void MGL_EXPORT mgl_data_clean(HMDT dat, long id); void MGL_EXPORT mgl_data_clean_(uintptr_t *dat, int *id); @@ -460,24 +506,11 @@ mreal MGL_EXPORT mgl_find_root_txt_(const char *func, mreal *ini, const char *va /// Find roots for nonlinear equation defined by textual formula HMDT MGL_EXPORT mgl_data_roots(const char *func, HCDT ini, char var_id); uintptr_t MGL_EXPORT mgl_data_roots_(const char *func, uintptr_t *ini, const char *var_id,int,int); - -//----------------------------------------------------------------------------- -/// Create HMEX object for expression evaluating -HMEX MGL_EXPORT mgl_create_expr(const char *expr); -uintptr_t MGL_EXPORT mgl_create_expr_(const char *expr, int); -/// Delete HMEX object -void MGL_EXPORT mgl_delete_expr(HMEX ex); -void MGL_EXPORT mgl_delete_expr_(uintptr_t *ex); -/// Return value of expression for given x,y,z variables -double MGL_EXPORT mgl_expr_eval(HMEX ex, double x, double y,double z); -double MGL_EXPORT mgl_expr_eval_(uintptr_t *ex, mreal *x, mreal *y, mreal *z); -/// Return value of expression for given variables -double MGL_EXPORT mgl_expr_eval_v(HMEX ex, mreal *vars); -/// Return value of expression differentiation over variable dir for given x,y,z variables -double MGL_EXPORT mgl_expr_diff(HMEX ex, char dir, double x, double y,double z); -double MGL_EXPORT mgl_expr_diff_(uintptr_t *ex, const char *dir, mreal *x, mreal *y, mreal *z, int); -/// Return value of expression differentiation over variable dir for given variables -double MGL_EXPORT mgl_expr_diff_v(HMEX ex, char dir, mreal *vars); +/// Find roots for set of nonlinear equations defined by textual formulas +HMDT MGL_EXPORT mgl_find_roots_txt(const char *func, const char *vars, HCDT ini); +uintptr_t MGL_EXPORT mgl_find_roots_txt_(const char *func, const char *vars, uintptr_t *ini,int,int); +/// Find roots for set of nonlinear equations defined by function +bool MGL_EXPORT mgl_find_roots(size_t n, void (*func)(const mreal *x, mreal *f, void *par), mreal *x0, void *par); //----------------------------------------------------------------------------- #ifdef __cplusplus } diff --git a/include/mgl2/datac.h b/include/mgl2/datac.h index 39670cc..64e3e1d 100644 --- a/include/mgl2/datac.h +++ b/include/mgl2/datac.h @@ -40,15 +40,14 @@ using mglDataA::Momentum; long ny; ///< number of points in 2nd dimensions ('y' dimension) long nz; ///< number of points in 3d dimensions ('z' dimension) dual *a; ///< data array - std::string id; ///< column (or slice) names bool link; ///< use external data (i.e. don't free it) /// Initiate by other mglDataC variable mglDataC(const mglDataC &d) { a=0; mgl_datac_set(this,&d); } // NOTE: must be constructor for mglDataC& to exclude copy one mglDataC(const mglDataA &d) { a=0; mgl_datac_set(this,&d); } #if MGL_HAVE_RVAL - mglDataC(mglDataC &&d):nx(d.nx),ny(d.ny),nz(d.nz),a(d.a),id(d.id),link(d.link) - { s=d.s; temp=d.temp; func=d.func; o=d.o; d.a=0; d.func=0; } + mglDataC(mglDataC &&d):nx(d.nx),ny(d.ny),nz(d.nz),a(d.a),link(d.link) + { s=d.s; temp=d.temp; func=d.func; o=d.o; id=d.id; d.a=0; d.func=0; } #endif mglDataC(const mglDataA &re, const mglDataA &im) { a=0; mgl_datac_set_ri(this,&re,&im); } mglDataC(HCDT d) { a=0; mgl_datac_set(this, d); } @@ -165,6 +164,9 @@ using mglDataA::Momentum; /// Crop the data inline void Crop(long n1, long n2,char dir='x') { mgl_datac_crop(this,n1,n2,dir); } + /// Crop the data to be most optimal for FFT (i.e. to closest value of 2^n*3^m*5^l) + inline void Crop(const char *how="235x") + { mgl_datac_crop_opt(this, how); } /// Insert data inline void Insert(char dir, long at=0, long num=1) { mgl_datac_insert(this,dir,at,num); } @@ -223,12 +225,6 @@ using mglDataA::Momentum; inline void Put(const mglDataA &dat, long i=-1, long j=-1, long k=-1) { mgl_datac_put_dat(this,&dat,i,j,k); } - /// Set names for columns (slices) - inline void SetColumnId(const char *ids) - { mgl_datac_set_id(this,ids); } - /// Make new id - inline void NewId() { id.clear(); } - /// Read data from tab-separated text file with auto determining size inline bool Read(const char *fname) { return mgl_datac_read(this,fname); } @@ -290,6 +286,13 @@ using mglDataA::Momentum; { return mglDataC(true,mgl_datac_subdata_ext(this,&xx,&yy,0)); } inline mglDataC SubData(const mglDataA &xx) const { return mglDataC(true,mgl_datac_subdata_ext(this,&xx,0,0)); } + /// Get data from sections ids, separated by value val along specified direction. + /** If section id is negative then reverse order is used (i.e. -1 give last section). */ + inline mglDataC Section(const mglDataA &ids, char dir='y', mreal val=NAN) const + { return mglDataC(true,mgl_datac_section(this,&ids,dir,val)); } + inline mglDataC Section(long id, char dir='y', mreal val=NAN) const + { return mglDataC(true,mgl_datac_section_val(this,id,dir,val)); } + /// Get trace of the data array inline mglDataC Trace() const { return mglDataC(true,mgl_datac_trace(this)); } @@ -329,6 +332,9 @@ using mglDataA::Momentum; /// Get array which is result of minimal values in given direction or directions inline mglData Min(const char *dir) const { return mglData(true,mgl_data_min_dir(this,dir)); } + /// Find roots for set of nonlinear equations defined by textual formula + inline mglDataC MultiRoots(const char *eq, const char *vars) const + { return mglDataC(true,mgl_find_roots_txt_c(eq, vars, this)); } /// Cumulative summation the data in given direction or directions inline void CumSum(const char *dir) { mgl_datac_cumsum(this,dir); } @@ -336,6 +342,15 @@ using mglDataA::Momentum; inline void Integral(const char *dir) { mgl_datac_integral(this,dir); } /// Differentiate the data in given direction or directions inline void Diff(const char *dir) { mgl_datac_diff(this,dir); } + /// Differentiate the parametrically specified data along direction v1 + inline void Diff(const mglDataA &v1) + { mgl_datac_diff_par(this,&v1,0,0); } + /// Differentiate the parametrically specified data along direction v1 with v2=const + inline void Diff(const mglDataA &v1, const mglDataA &v2) + { mgl_datac_diff_par(this,&v1,&v2,0); } + /// Differentiate the parametrically specified data along direction v1 with v2,v3=const + inline void Diff(const mglDataA &v1, const mglDataA &v2, const mglDataA &v3) + { mgl_datac_diff_par(this,&v1,&v2,&v3); } /// Double-differentiate (like laplace operator) the data in given direction inline void Diff2(const char *dir) { mgl_datac_diff2(this,dir); } @@ -358,12 +373,26 @@ using mglDataA::Momentum; inline void Limit(mreal v) { mgl_datac_limit(this, v); } + /// Set as the data envelop + inline void Envelop(char dir='x') { mgl_datac_envelop(this,dir); } /// Hankel transform inline void Hankel(const char *dir) { mgl_datac_hankel(this,dir); } + /// Apply Sin-Fourier transform + inline void SinFFT(const char *dir) { mgl_datac_sinfft(this,dir); } + /// Apply Cos-Fourier transform + inline void CosFFT(const char *dir) { mgl_datac_cosfft(this,dir); } /// Fourier transform inline void FFT(const char *dir) { mgl_datac_fft(this,dir); } /// Calculate one step of diffraction by finite-difference method with parameter q inline void Diffraction(const char *how, mreal q) { mgl_datac_diffr(this,how,q); } + /// Apply wavelet transform + /** Parameter \a dir may contain: + * ‘x‘,‘y‘,‘z‘ for directions, + * ‘d‘ for daubechies, ‘D‘ for centered daubechies, + * ‘h‘ for haar, ‘H‘ for centered haar, + * ‘b‘ for bspline, ‘B‘ for centered bspline, + * ‘i‘ for applying inverse transform. */ + inline void Wavelet(const char *how, int k) { mgl_datac_wavelet(this, how, k); } /// Interpolate by cubic spline the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] inline dual Spline(mreal x,mreal y=0,mreal z=0) const @@ -433,7 +462,8 @@ using mglDataA::Momentum; inline void operator-=(dual d) { mgl_datac_sub_num(this,d); } #ifndef SWIG /// Direct access to the data cell - inline dual &operator[](long i) { return a[i]; } + inline dual operator[](long i) const { return a[i]; } + inline dual &operator[](long i) { return a[i]; } #endif @@ -457,21 +487,25 @@ using mglDataA::Momentum; aa = mglSpline3C(a,nx,ny,nz,x,y,z,&ax,&ay,&az); res = abs(aa); if(dx) *dx = res?(real(aa)*real(ax)+imag(aa)*imag(ax))/res:0; if(dy) *dy = res?(real(aa)*real(ay)+imag(aa)*imag(ay))/res:0; - if(dz) *dz = res?(real(aa)*real(az)+imag(aa)*imag(az))/res:0; return res; } + if(dz) *dz = res?(real(aa)*real(az)+imag(aa)*imag(az))/res:0; + return res; } /// Get the interpolated value in given data cell without border checking mreal value(mreal x,mreal y=0,mreal z=0) const { return abs(mglSpline3Cs(a,nx,ny,nz,x,y,z)); } mreal vthr(long i) const { return abs(a[i]); } // add for speeding up !!! mreal dvx(long i,long j=0,long k=0) const - { register long i0=i+nx*(j+ny*k); - return i>0? abs(i0? abs(i0? abs(j0? abs(j0? abs(k0? abs(k + #define _(x) gettext(x) +#else + #define _(x) (x) #endif -#ifdef MGL_SRC + #if MGL_HAVE_ZLIB #include #ifndef Z_BEST_COMPRESSION @@ -104,6 +120,10 @@ typedef unsigned long long uint64_t; typedef unsigned long uintptr_t; #endif +#if ((defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(M_PI)) //_MSC_VER needs this before math.h +#define _USE_MATH_DEFINES +#endif + #include #include #include @@ -111,6 +131,7 @@ typedef unsigned long uintptr_t; #include #if defined(_MSC_VER) +typedef long msize; #define collapse(a) // MSVS don't support OpenMP 3.* #if (_MSC_VER<=1800) #define strtoull _strtoui64 @@ -122,6 +143,8 @@ typedef unsigned long uintptr_t; #if (_MSC_VER<1600) // based on https://hg.python.org/cpython/rev/9aedb876c2d7 #define hypot _hypot #endif +#else +typedef size_t msize; #endif #if !MGL_SYS_NAN @@ -181,28 +204,6 @@ typedef float mreal; #define MGL_DEF_VIEWER "evince" #endif //----------------------------------------------------------------------------- -#if MGL_HAVE_TYPEOF -#define mgl_isrange(a,b) ({typeof (a) _a = (a); typeof (b) _b = (b); fabs(_a-_b)>MGL_MIN_VAL && _a-_a==mreal(0.) && _b-_b==mreal(0.);}) -#define mgl_isbad(a) ({typeof (a) _a = (a); _a-_a!=mreal(0.);}) -#define mgl_isfin(a) ({typeof (a) _a = (a); _a-_a==mreal(0.);}) -#define mgl_isnum(a) ({typeof (a) _a = (a); _a==_a;}) -#define mgl_isnan(a) ({typeof (a) _a = (a); _a!=_a;}) -#define mgl_min(a,b) ({typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _b : _a;}) -#define mgl_max(a,b) ({typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b;}) -#define mgl_sign(a) ({typeof (a) _a = (a); _a<0 ? -1:1;}) -#define mgl_int(a) ({typeof (a) _a = (a); long(_a+(_a>=0 ? 0.5:-0.5));}) -#else -#define mgl_isrange(a,b) (fabs((a)-(b))>MGL_EPSILON && (a)-(a)==mreal(0.) && (b)-(b)==mreal(0.)) -#define mgl_min(a,b) (((a)>(b)) ? (b) : (a)) -#define mgl_max(a,b) (((a)>(b)) ? (a) : (b)) -#define mgl_isnan(a) ((a)!=(a)) -#define mgl_isnum(a) ((a)==(a)) -#define mgl_isfin(a) ((a)-(a)==mreal(0.)) -#define mgl_isbad(a) ((a)-(a)!=mreal(0.)) -#define mgl_sign(a) ((a)<0 ? -1:1) -#define mgl_int(a) (long(a+((a)>=0 ? 0.5:-0.5))) -#endif -//----------------------------------------------------------------------------- enum{ // types of predefined curvelinear coordinate systems mglCartesian = 0, // no transformation mglPolar, @@ -259,34 +260,36 @@ enum{ // Codes for warnings/messages #define MGL_COLORS "kwrgbcymhWRGBCYMHlenpquLENPQU" //----------------------------------------------------------------------------- /// Brushes for mask with symbol "-+=;oOsS~<>jdD*^" correspondingly -extern uint64_t mgl_mask_val[16]; +extern MGL_EXPORT uint64_t mgl_mask_val[16]; #define MGL_MASK_ID "-+=;oOsS~<>jdD*^" #define MGL_SOLID_MASK 0xffffffffffffffff //----------------------------------------------------------------------------- -#define MGL_TRANSP_NORM 0x000000 -#define MGL_TRANSP_GLASS 0x000001 -#define MGL_TRANSP_LAMP 0x000002 -#define MGL_ENABLE_CUT 0x000004 ///< Flag which determines how points outside bounding box are drown. -#define MGL_ENABLE_RTEXT 0x000008 ///< Use text rotation along axis -#define MGL_AUTO_FACTOR 0x000010 ///< Enable autochange PlotFactor -#define MGL_ENABLE_ALPHA 0x000020 ///< Flag that Alpha is used -#define MGL_ENABLE_LIGHT 0x000040 ///< Flag of using lightning -#define MGL_TICKS_ROTATE 0x000080 ///< Allow ticks rotation -#define MGL_TICKS_SKIP 0x000100 ///< Allow ticks rotation +#define MGL_TRANSP_NORM 0x00000000 +#define MGL_TRANSP_GLASS 0x00000001 +#define MGL_TRANSP_LAMP 0x00000002 +#define MGL_ENABLE_CUT 0x00000004 ///< Flag which determines how points outside bounding box are drown. +#define MGL_ENABLE_RTEXT 0x00000008 ///< Use text rotation along axis +#define MGL_AUTO_FACTOR 0x00000010 ///< Enable autochange PlotFactor +#define MGL_ENABLE_ALPHA 0x00000020 ///< Flag that Alpha is used +#define MGL_ENABLE_LIGHT 0x00000040 ///< Flag of using lightning +#define MGL_TICKS_ROTATE 0x00000080 ///< Allow ticks rotation +#define MGL_TICKS_SKIP 0x00000100 ///< Allow ticks rotation // flags for internal use only -#define MGL_DISABLE_SCALE 0x000200 ///< Temporary flag for disable scaling (used for axis) -#define MGL_FINISHED 0x000400 ///< Flag that final picture (i.e. mglCanvas::G) is ready -#define MGL_USE_GMTIME 0x000800 ///< Use gmtime instead of localtime -#define MGL_SHOW_POS 0x001000 ///< Switch to show or not mouse click position -#define MGL_CLF_ON_UPD 0x002000 ///< Clear plot before Update() -#define MGL_NOSUBTICKS 0x004000 ///< Disable subticks drawing (for bounding box) -#define MGL_LOCAL_LIGHT 0x008000 ///< Keep light sources for each inplot -#define MGL_VECT_FRAME 0x010000 ///< Use DrwDat to remember all data of frames -#define MGL_REDUCEACC 0x020000 ///< Reduce accuracy of points (to reduc size of output files) -#define MGL_PREFERVC 0x040000 ///< Prefer vertex color instead of texture if output format supports -#define MGL_ONESIDED 0x080000 ///< Render only front side of surfaces if output format supports (for debugging) -#define MGL_NO_ORIGIN 0x100000 ///< Don't draw tick labels at axis origin -#define MGL_GRAY_MODE 0x100000 ///< Convert all colors to gray ones +#define MGL_DISABLE_SCALE 0x00000200 ///< Temporary flag for disable scaling (used for axis) +#define MGL_FINISHED 0x00000400 ///< Flag that final picture (i.e. mglCanvas::G) is ready +#define MGL_USE_GMTIME 0x00000800 ///< Use gmtime instead of localtime +#define MGL_SHOW_POS 0x00001000 ///< Switch to show or not mouse click position +#define MGL_CLF_ON_UPD 0x00002000 ///< Clear plot before Update() +#define MGL_NOSUBTICKS 0x00004000 ///< Disable subticks drawing (for bounding box) +#define MGL_LOCAL_LIGHT 0x00008000 ///< Keep light sources for each inplot +#define MGL_VECT_FRAME 0x00010000 ///< Use DrwDat to remember all data of frames +#define MGL_REDUCEACC 0x00020000 ///< Reduce accuracy of points (to reduce size of output files) +#define MGL_PREFERVC 0x00040000 ///< Prefer vertex color instead of texture if output format supports +#define MGL_ONESIDED 0x00080000 ///< Render only front side of surfaces if output format supports (for debugging) +#define MGL_NO_ORIGIN 0x00100000 ///< Don't draw tick labels at axis origin +#define MGL_GRAY_MODE 0x00200000 ///< Convert all colors to gray ones +#define MGL_FULL_CURV 0x00400000 ///< Disable omitting points in straight-line part(s). +#define MGL_NO_SCALE_REL 0x00800000 ///< Disable font scaling in relative inplots //----------------------------------------------------------------------------- #if MGL_HAVE_C99_COMPLEX #include @@ -304,24 +307,24 @@ const mdual mgl_I=_Complex_I; #ifdef __cplusplus #include #include -#if defined(_MSC_VER) -template class MGL_EXPORT std::allocator; -template class MGL_EXPORT std::allocator; -template struct MGL_EXPORT std::char_traits; -template struct MGL_EXPORT std::char_traits; -template class MGL_EXPORT std::basic_string< char, std::char_traits, std::allocator >; -template class MGL_EXPORT std::basic_string< wchar_t, std::char_traits, std::allocator >; -template class MGL_EXPORT std::vector; -template class MGL_EXPORT std::vector; -#endif +// #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) +// MGL_EXTERN template class MGL_EXPORT std::allocator; +// MGL_EXTERN template class MGL_EXPORT std::allocator; +// MGL_EXTERN template struct MGL_EXPORT std::char_traits; +// MGL_EXTERN template struct MGL_EXPORT std::char_traits; +// MGL_EXTERN template class MGL_EXPORT std::basic_string< char, std::char_traits, std::allocator >; +// MGL_EXTERN template class MGL_EXPORT std::basic_string< wchar_t, std::char_traits, std::allocator >; +// MGL_EXTERN template class MGL_EXPORT std::vector; +// MGL_EXTERN template class MGL_EXPORT std::vector; +// #endif //----------------------------------------------------------------------------- extern float mgl_cos[360]; ///< contain cosine with step 1 degree //----------------------------------------------------------------------------- #include -#if defined(_MSC_VER) -template class MGL_EXPORT std::complex; -template class MGL_EXPORT std::complex; -#endif +// #if defined(_MSC_VER) +// MGL_EXTERN template class MGL_EXPORT std::complex; +// MGL_EXTERN template class MGL_EXPORT std::complex; +// #endif typedef std::complex dual; typedef std::complex ddual; #if !MGL_HAVE_C99_COMPLEX @@ -330,6 +333,24 @@ typedef std::complex ddual; #define mgl_abs(x) abs(x) #endif //----------------------------------------------------------------------------- +inline bool mgl_isrange(double a, double b) +{ return fabs(a-b)>MGL_MIN_VAL && a-a==0. && b-b==0.; } +inline bool mgl_isbad(double a) { return a-a!=0; } +inline bool mgl_isbad(dual a) { return a-a!=mreal(0); } +inline bool mgl_isfin(double a) { return a-a==0; } +inline bool mgl_isfin(dual a) { return a-a==mreal(0); } +inline bool mgl_isnum(double a) { return a==a; } +inline bool mgl_isnum(dual a) { return a==a; } +inline bool mgl_isnan(double a) { return a!=a; } +inline bool mgl_isnan(dual a) { return a!=a; } +inline int mgl_sign(double a) { return a<0?-1:1; } +inline long mgl_int(double a) { return long(a+(a>=0?0.5:-0.5)); } +inline double mgl_min(double a, double b) { return a>b?b:a; } +inline double mgl_max(double a, double b) { return a>b?a:b; } +inline long mgl_imin(long a, long b) { return a>b?b:a; } +inline long mgl_imax(long a, long b) { return a>b?a:b; } +inline void mgl_strncpy(char *a, const char *b, size_t s) { strncpy(a,b,s); a[s-1]=0; } +//----------------------------------------------------------------------------- extern "C" { #else #include @@ -342,6 +363,8 @@ double MGL_EXPORT_CONST mgl_hypot(double x, double y); size_t MGL_EXPORT mgl_wcslen(const wchar_t *str); /// Get RGB values for given color id or fill by -1 if no one found void MGL_EXPORT mgl_chrrgb(char id, float rgb[3]); +/// Get number of colors in the string +size_t MGL_EXPORT mgl_get_num_color(const char *s, int smooth); /// Check if string contain color id and return its number long MGL_EXPORT mgl_have_color(const char *stl); /// Find symbol in string excluding {} and return its position or NULL @@ -369,6 +392,11 @@ void MGL_EXPORT mgl_set_global_warn_(const char *text,int); /// Get text of global warning message(s) MGL_EXPORT const char *mgl_get_global_warn(); int MGL_EXPORT mgl_get_global_warn_(char *out, int len); +/// Setup gettext usage. NOTE: Russian translation MUST be installed. +void MGL_EXPORT mgl_textdomain(const char *argv0, const char *locale); +void MGL_EXPORT mgl_textdomain_(const char *locale, int); +/// size of var array +const int MGL_VS = 'z'-'a'+1; #ifdef __cplusplus } #endif diff --git a/include/mgl2/eval.h b/include/mgl2/eval.h index 920c0c7..0910e93 100644 --- a/include/mgl2/eval.h +++ b/include/mgl2/eval.h @@ -25,8 +25,6 @@ #define MGL_ERR_LOG 1 #define MGL_ERR_ARC 2 #define MGL_ERR_SQRT 3 -/// size of var array -const int MGL_VS = 'z'-'a'+1; //----------------------------------------------------------------------------- /// Class for evaluating formula specified by the string class MGL_EXPORT mglFormula // îáúåêò äëÿ ââîäà è âû÷èñëåíèÿ ôîðìóë diff --git a/include/mgl2/fltk.h b/include/mgl2/fltk.h index 9d4a223..3b4ef74 100644 --- a/include/mgl2/fltk.h +++ b/include/mgl2/fltk.h @@ -33,8 +33,10 @@ int MGL_EXPORT mgl_fltk_run(); int MGL_EXPORT mgl_fltk_run_(); /// Run main FLTK loop for event handling in separate thread. int MGL_EXPORT mgl_fltk_thr(); -/// Callback function for asking user. +/// FLTK function for asking user. void MGL_EXPORT mgl_ask_fltk(const wchar_t *quest, wchar_t *res); +/// FLTK function for displaying progress of something. +void MGL_EXPORT mgl_progress_fltk(int value, int maximal, HMGL gr); /// Return pointer to widget (Fl_MGLView*) used for plotting MGL_EXPORT void *mgl_fltk_widget(HMGL gr); #ifdef __cplusplus diff --git a/include/mgl2/font.h b/include/mgl2/font.h index 8c0abdb..e735e24 100644 --- a/include/mgl2/font.h +++ b/include/mgl2/font.h @@ -50,9 +50,10 @@ struct mglGlyphDescr inline bool operator<(const mglGlyphDescr &a,const mglGlyphDescr &b) { return a.id(const mglGlyphDescr &a,const mglGlyphDescr &b) { return a.id>b.id; } #if defined(_MSC_VER) -template class MGL_EXPORT std::vector; +MGL_EXTERN template class MGL_EXPORT std::vector; #endif //----------------------------------------------------------------------------- +extern const float mgl_fact; struct MGL_EXPORT mglTeXsymb { unsigned kod; const wchar_t *tex; }; const float mgl_fgen = 4*14; /// Get font color, style and align for internal parser diff --git a/include/mgl2/mgl.h b/include/mgl2/mgl.h index 023cd84..c83b6ee 100644 --- a/include/mgl2/mgl.h +++ b/include/mgl2/mgl.h @@ -34,8 +34,9 @@ class MGL_EXPORT mglGraph protected: HMGL gr; public: + HMPR pr; ///< Pointer to associated MGL parser mglGraph(int kind=0, int width=600, int height=400) - { + { pr = NULL; if(kind==-1) gr=NULL; #if MGL_HAVE_OPENGL else if(kind==1) gr=mgl_create_graph_gl(); @@ -47,7 +48,7 @@ public: else gr=mgl_create_graph(width, height); } mglGraph(HMGL graph) - { gr = graph; mgl_use_graph(gr,1); } + { pr = NULL; gr = graph; mgl_use_graph(gr,1); } virtual ~mglGraph() { if(mgl_use_graph(gr,-1)<1) mgl_delete_graph(gr); } /// Get pointer to internal HMGL object @@ -118,7 +119,7 @@ public: inline void CutOff(const char *EqC) { mgl_set_cutoff(gr, EqC); } /// Set default font size - inline void SetFontSize(double size) { mgl_set_font_size(gr, size);} + inline void SetFontSize(double size) { mgl_set_font_size(gr, size); } /// Set default font style and color inline void SetFontDef(const char *fnt) { mgl_set_font_def(gr, fnt); } /// Set FontSize by size in pt and picture DPI (default is 16 pt for dpi=72) @@ -135,9 +136,14 @@ public: /// Restore font (load default font for new HMGL objects) inline void RestoreFont() { mgl_restore_font(gr); } /// Set to use or not text rotation - inline void SetRotatedText(bool rotated) { mgl_set_rotated_text(gr, rotated); } + inline void SetRotatedText(bool enable) { mgl_set_rotated_text(gr, enable); } + /// Set to scale text in relative subplots too + inline void SetScaleText(bool enable) { mgl_set_scale_text(gr, enable); } /// Set default font for all new HMGL and mglGraph objects static inline void SetDefFont(const char *name, const char *path=NULL) { mgl_def_font(name,path); } + /// Add user-defined glyph for symbol and set its optional id + inline void DefineSymbol(char id, const mglDataA &x, const mglDataA &y) + { mgl_define_symbol(gr, id, &x, &y); } /// Set default palette inline void SetPalette(const char *colors) { mgl_set_palette(gr, colors); } @@ -167,6 +173,8 @@ public: static inline void SuppressWarn(bool on) { mgl_suppress_warn(on); } /// Check if MathGL version is valid (return false) or not (return true) static inline bool CheckVersion(const char *ver) { return mgl_check_version(ver); } + /// Display progress of something. + inline void Progress(int value, int maximal) { mgl_progress(value, maximal, gr); } /// Set axis range scaling -- simplified way to shift/zoom axis range -- need to replot whole image! inline void ZoomAxis(mglPoint p1=mglPoint(0,0,0,0), mglPoint p2=mglPoint(1,1,1,1)) @@ -274,6 +282,9 @@ public: /// Set to draw tick labels at axis origin inline void SetOriginTick(bool enable=true) { mgl_set_flag(gr,!enable, MGL_NO_ORIGIN); } + /// Set bit-value flag of HMGL state (for advanced users only) + inline void SetFlagAdv(int val, uint32_t flag) + { mgl_set_flag(gr, val, flag); } /// Put further plotting in m-th cell of nx*ny grid of the image. /** String \a style may contain: @@ -284,15 +295,15 @@ public: * '#' for using whole region. */ inline void SubPlot(int nx,int ny,int m,const char *style="<>_^", double dx=0, double dy=0) { mgl_subplot_d(gr, nx, ny, m, style, dx, dy); } - /// Put further plotting in rectangle of dx*dy cells starting from m-th cell of nx*ny grid of the image. + /// Put further plotting in rectangle of dx*dy cells starting from m-th cell of nx*ny grid of the image and shift it by distance {sx,sy}. /** String \a style may contain: * '<' for reserving space at left * '>' for reserving space at right * '^' for reserving space at top * '_' for reserving space at bottom * '#' for using whole region. */ - inline void MultiPlot(int nx,int ny,int m, int dx, int dy, const char *style="<>_^") - { mgl_multiplot(gr, nx, ny, m, dx, dy, style); } + inline void MultiPlot(int nx,int ny,int m, int dx, int dy, const char *style="<>_^", double sx=0, double sy=0) + { mgl_multiplot_d(gr, nx, ny, m, dx, dy, style, sx, sy); } /// Put further plotting in a region [x1,x2]*[y1,y2] of the image or subplot (x1,x2,y1,y2 in range [0, 1]). inline void InPlot(double x1,double x2,double y1,double y2, bool rel=true) { if(rel) mgl_relplot(gr, x1, x2, y1, y2); @@ -369,11 +380,16 @@ public: /// Set drawing region for Quality&4 inline void SetDrawReg(long nx=1, long ny=1, long m=0) { mgl_set_draw_reg(gr,nx,ny,m); } /// Start group of objects - inline void StartGroup(const char *name) { mgl_start_group(gr, name); } + inline void StartGroup(const char *name) { mgl_start_group(gr, name); } /// End group of objects inline void EndGroup() { mgl_end_group(gr); } /// Highlight objects with given id inline void Highlight(int id) { mgl_highlight(gr, id); } + /// Set boundary box for export graphics into 2D file formats. + /** If x2<0 (y2<0) then full width (height) will be used. + * If x1<0 or y1<0 or x1>=x2|Width or y1>=y2|Height then cropping will be disabled. */ + inline void SetBBox(int x1=0, int y1=0, int x2=-1, int y2=-1) + { mgl_set_bbox(gr,x1,y1,x2,y2); } /// Show current image inline void ShowImage(const char *viewer, bool keep=0) @@ -596,6 +612,18 @@ public: inline void Bifurcation(double dx, const char *func, const char *stl="", const char *opt="") { mgl_bifurcation_str(gr,dx,func,stl,opt); } + /// Draws Iris plots for determining cross-dependences of data arrays + /** NOTE: using the same ranges and empty ids will not draw axis. This will add data to existing Iris plot. + * Option value set the size of data labels ids, separated by ';'.*/ + inline void Iris(mglDataA &dats, const char *ids, const char *stl="", const char *opt="") + { mgl_iris_1(gr,&dats,ids,stl,opt); } + inline void Iris(mglDataA &dats, const wchar_t *ids, const char *stl="", const char *opt="") + { mgl_irisw_1(gr,&dats,ids,stl,opt); } + inline void Iris(mglDataA &dats, mglDataA &ranges, const char *ids, const char *stl="", const char *opt="") + { mgl_iris(gr,&dats,&ranges,ids,stl,opt); } + inline void Iris(mglDataA &dats, mglDataA &ranges, const wchar_t *ids, const char *stl="", const char *opt="") + { mgl_irisw(gr,&dats,&ranges,ids,stl,opt); } + /// Draws the face between points with color stl (include interpolation up to 4 colors). inline void Face(mglPoint p1, mglPoint p2, mglPoint p3, mglPoint p4, const char *stl="r") { mgl_face(gr, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, p4.x, p4.y, p4.z, stl); } @@ -648,8 +676,8 @@ public: inline void Polygon(mglPoint p1, mglPoint p2, int n, const char *stl="r") { mgl_polygon(gr, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, n,stl); } /// Draws the arc around axis pr with center at p0 and starting from p1, by color stl and angle a (in degrees) - inline void Arc(mglPoint p0, mglPoint pr, mglPoint p1, double a, const char *stl="r") - { mgl_arc_ext(gr, p0.x,p0.y,p0.z, pr.x,pr.y,pr.z, p1.x,p1.y,p1.z, a,stl); } + inline void Arc(mglPoint p0, mglPoint pa, mglPoint p1, double a, const char *stl="r") + { mgl_arc_ext(gr, p0.x,p0.y,p0.z, pa.x,pa.y,pa.z, p1.x,p1.y,p1.z, a,stl); } /// Draws the arc around axis 'z' with center at p0 and starting from p1, by color stl and angle a (in degrees) inline void Arc(mglPoint p0, mglPoint p1, double a, const char *stl="r") { mgl_arc_ext(gr, p0.x,p0.y,p0.z, 0,0,1, p1.x,p1.y,p0.z, a,stl); } @@ -659,6 +687,13 @@ public: inline void Logo(const char *fname, bool smooth=false, const char *opt="") { mgl_logo_file(gr, fname, smooth, opt); } + /// Draw user-defined symbol in position p + inline void Symbol(mglPoint p, char id, const char *how="", double size=-1) + { mgl_symbol(gr, p.x, p.y, p.z, id, how, size); } + /// Draw user-defined symbol in position p along direction d + inline void Symbol(mglPoint p, mglPoint d, char id, const char *how="", double size=-1) + { mgl_symbol_dir(gr, p.x, p.y, p.z, d.x, d.y, d.z, id, how, size); } + /// Print text in position p with specified font inline void Putsw(mglPoint p,const wchar_t *text,const char *font=":C",double size=-1) { mgl_putsw(gr, p.x, p.y, p.z, text, font, size); } @@ -1255,6 +1290,14 @@ public: /** Style 'x' draw belts in x-direction. */ inline void Belt(const mglDataA &z, const char *stl="", const char *opt="") { mgl_belt(gr, &z, stl, opt); } + /// Draw belts for 2d data specified parametrically with color proportional to c + /** Style 'x' draw belts in x-direction. */ + inline void BeltC(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &c, const char *stl="", const char *opt="") + { mgl_beltc_xy(gr, &x, &y, &z, &c, stl, opt); } + /// Draw belts for 2d data with color proportional to c + /** Style 'x' draw belts in x-direction. */ + inline void BeltC(const mglDataA &z, const mglDataA &c, const char *stl="", const char *opt="") + { mgl_beltc(gr, &z, &c, stl, opt); } /// Draw surface for 2d data specified parametrically with color proportional to z /** Style ‘#’ draw grid lines. Style ‘.’ produce plot by dots.*/ @@ -1272,6 +1315,9 @@ public: inline void Grid(const mglDataA &z, const char *stl="", const char *opt="") { mgl_grid(gr, &z, stl, opt); } + /// Draw vertical tiles with manual colors c for 2d data specified parametrically + inline void Tile(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &c, const char *stl="", const char *opt="") + { mgl_tile_xyc(gr, &x, &y, &z, &c, stl, opt); } /// Draw vertical tiles for 2d data specified parametrically inline void Tile(const mglDataA &x, const mglDataA &y, const mglDataA &z, const char *stl="", const char *opt="") { mgl_tile_xy(gr, &x, &y, &z, stl, opt); } @@ -1297,6 +1343,19 @@ public: inline void Boxs(const mglDataA &z, const char *stl="", const char *opt="") { mgl_boxs(gr, &z, stl, opt); } + /// Draw contour lines on parametric surface at manual levels for 2d data specified parametrically + /** Style ‘f’ to draw solid contours. + * Style 't'/'T' draw contour labels below/above contours.*/ + inline void ContP(const mglDataA &v, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", const char *opt="") + { mgl_contp_val(gr, &v, &x, &y, &z, &a, sch, opt); } + /// Draw contour lines on parametric surface at manual levels for 2d data specified parametrically + /** Style ‘f’ to draw solid contours. + * Style ‘t’/‘T’ draw contour labels below/above contours. + * Option "value" set the number of contour levels (default is 7). */ + inline void ContP(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", const char *opt="") + { mgl_contp(gr, &x, &y, &z, &a, sch, opt); } + + /// Draw contour lines at manual levels for 2d data specified parametrically /** Style ‘_’ to draw contours at bottom of axis box. * Style 't'/'T' draw contour labels below/above contours.*/ @@ -1517,6 +1576,9 @@ public: inline void Beam(double val, const mglDataA &tr, const mglDataA &g1, const mglDataA &g2, const mglDataA &a, double r, const char *stl=NULL, int flag=0) { mgl_beam_val(gr,val,&tr,&g1,&g2,&a,r,stl,flag); } + /// Draw vertical tiles with variable size r and manual colors c for 2d data specified parametrically + inline void TileS(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &r, const mglDataA &c, const char *stl="", const char *opt="") + { mgl_tiles_xyc(gr, &x, &y, &z, &r, &c, stl, opt); } /// Draw vertical tiles with variable size r for 2d data specified parametrically inline void TileS(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &r, const char *stl="", const char *opt="") { mgl_tiles_xy(gr, &x, &y, &z, &r, stl, opt); } @@ -1762,6 +1824,23 @@ public: inline void FlowP(mglPoint p, const mglDataA &ax, const mglDataA &ay, const mglDataA &az, const char *sch="", const char *opt="") { mgl_flowp_3d(gr, p.x, p.y, p.z, &ax, &ay, &az, sch, opt); } + /// Plot flows from given plain for vector field {ax,ay,az} parametrically depended on coordinate {x,y,z} with color proportional to |a| + /** String \a sch may contain: + * color scheme: up-half (warm) corresponds to normal flow (like attractor), bottom-half (cold) corresponds to inverse flow (like source); + * 'v' for drawing arrows on the threads; + * 't' for drawing tapes of normals in x-y and y-z planes. + * Option "value" sets the number of threads (default is 5). */ + inline void Flow3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &ax, const mglDataA &ay, const mglDataA &az, const char *sch="", double sVal=-1, const char *opt="") + { mgl_flow3_xyz(gr, &x, &y, &z, &ax, &ay, &az, sch, sVal, opt); } + /// Plot flows from given plain for vector field {ax,ay,az} with color proportional to |a| + /** String \a sch may contain: + * color scheme: up-half (warm) corresponds to normal flow (like attractor), bottom-half (cold) corresponds to inverse flow (like source); + * 'v' for drawing arrows on the threads; + * 't' for drawing tapes of normals in x-y and y-z planes. + * Option "value" sets the number of threads (default is 5). */ + inline void Flow3(const mglDataA &ax, const mglDataA &ay, const mglDataA &az, const char *sch="", double sVal=-1, const char *opt="") + { mgl_flow3(gr, &ax, &ay, &az, sch, sVal, opt); } + /// Plot flows for gradient of scalar field phi parametrically depended on coordinate {x,y,z} /** String \a sch may contain: * color scheme: up-half (warm) corresponds to normal flow (like attractor), bottom-half (cold) corresponds to inverse flow (like source); @@ -2144,6 +2223,8 @@ public: class MGL_EXPORT mglParse { HMPR pr; + mglParse &operator=(mglParse &p) + { pr = p.pr; mgl_use_parser(pr,1); return p; } public: mglParse(HMPR p) { pr = p; mgl_use_parser(pr,1); } mglParse(mglParse &p) { pr = p.pr; mgl_use_parser(pr,1); } @@ -2182,7 +2263,7 @@ public: /// Return description of MGL command inline const char *CmdDesc(const char *name) { return mgl_parser_cmd_desc(pr, name); } - /// Get name of command with nmber n + /// Get name of command with number n inline const char *GetCmdName(long n) { return mgl_parser_cmd_name(pr,n); } /// Get number of defined commands @@ -2196,6 +2277,9 @@ public: { mgl_rk_step(pr, eqs, vars, dt); } inline void RK_Step(const wchar_t *eqs, const wchar_t *vars, mreal dt=1) { mgl_rk_step_w(pr, eqs, vars, dt); } + // Open all data arrays from HDF file and assign it as variables of parser p + inline void OpenHDF(const char *fname) + { mgl_parser_openhdf(pr, fname); } /// Set value for parameter $N inline void AddParam(int id, const char *str) @@ -2215,7 +2299,10 @@ public: /// Set variant of argument(s) separated by '?' to be used in further commands inline void SetVariant(int var=0) { mgl_parser_variant(pr, var); } - + /// Set starting object ID + inline void StartID(int id=0) + { mgl_parser_start_id(pr, id); } + /// Return result of formula evaluation inline mglData Calc(const char *formula) { return mglData(true,mgl_parser_calc(pr,formula)); } @@ -2252,6 +2339,14 @@ public: inline void DeleteVar(const wchar_t *name) { mgl_parser_del_varw(pr, name); } /// Delete all data variables void DeleteAll() { mgl_parser_del_all(pr); } + + /// Get constant with given id. Can be NULL if not found. + /// NOTE !!! You must not delete obtained data arrays !!! + inline mglNum *GetConst(unsigned long id) + { return mgl_parser_get_const(pr,id); } + /// Get number of constants + inline long GetNumConst() + { return mgl_parser_num_const(pr); } }; //----------------------------------------------------------------------------- #endif diff --git a/include/mgl2/opengl.h b/include/mgl2/opengl.h index a1b1354..98cf1f4 100644 --- a/include/mgl2/opengl.h +++ b/include/mgl2/opengl.h @@ -56,7 +56,8 @@ protected: void quad_draw(const mglPnt &p1, const mglPnt &p2, const mglPnt &p3, const mglPnt &p4, const mglDrawReg *d); void pnt_draw(const mglPnt &p, const mglDrawReg *d); void mark_draw(const mglPnt &q, char type, mreal size, mglDrawReg *d); - + void glyph_fill(mreal phi, const mglPnt &p, mreal f, const mglGlyph &g, const mglDrawReg *d); + unsigned char **GetRGBLines(long &w, long &h, unsigned char *&f, bool solid=true); void LightScale(const mglMatrix *M); diff --git a/include/mgl2/parser.h b/include/mgl2/parser.h index fe21f80..488c577 100644 --- a/include/mgl2/parser.h +++ b/include/mgl2/parser.h @@ -31,8 +31,7 @@ struct mglArg { int type; ///< Type of argument {0-data,1-string,2-number} mglDataA *d; ///< Pointer to data (used if type==0) - std::wstring w; ///< String with parameters - std::string s; ///< String with parameters + mglString s; ///< String with parameters mreal v; ///< Numerical value (used if type==2) dual c; ///< Numerical complex value (used if type==2) mglArg():type(-1),d(0),v(0),c(0.) {} @@ -46,40 +45,52 @@ struct mglCommand const char *form; ///< Format of command arguments (can be NULL) /// Function for executing (plotting) int (*exec)(mglGraph *gr, long n, mglArg *a, const char *k, const char *opt); - /// Type of command: 0 - data plot, 1 - other plot, + /// Type of command: 0 - special plot, 1 - other plot, /// 2 - setup, 3 - data handle, 4 - data create, 5 - subplot, 6 - program /// 7 - 1d plot, 8 - 2d plot, 9 - 3d plot, 10 - dd plot, 11 - vector plot /// 12 - axis, 13 - primitives, 14 - axis setup, 15 - text/legend, 16 - data transform int type; }; -extern mglCommand mgls_base_cmd[]; -//----------------------------------------------------------------------------- -/// Structure for the number handling (see mglParse class). -struct mglNum -{ - mreal d; ///< Number itself - dual c; - std::wstring s; ///< Number name - mglNum(mreal val=0):d(val),c(val) {} -}; +extern mglCommand mgls_prg_cmd[], mgls_dat_cmd[], mgls_grf_cmd[], mgls_set_cmd[], mgls_prm_cmd[]; //----------------------------------------------------------------------------- /// Structure for function name and position. struct mglFunc { long pos; int narg; - std::wstring func; + mglString func; mglFunc(long p, const wchar_t *f); mglFunc(const mglFunc &f):pos(f.pos),narg(f.narg),func(f.func) {} mglFunc():pos(-1),narg(-1) {} + const mglFunc &operator=(const mglFunc &f) + { pos=f.pos; narg=f.narg; func=f.func; return f; } }; //----------------------------------------------------------------------------- /// Structure for stack of functions and its arguments. struct mglFnStack { - long pos; - std::wstring par[10]; - mglFnStack():pos(0) {} + long pos; ///< position to return + size_t stk; ///< stack at 'call' + mglString par[10]; ///< input parameters + mglFnStack():pos(0),stk(0) {} +}; +//----------------------------------------------------------------------------- +/// Structure for stack of if|for|while. +#define MGL_ST_TRUE 0 // condition true +#define MGL_ST_FALSE 1 // condition false +#define MGL_ST_DONE 2 // condition done +#define MGL_ST_LOOP 4 // normal loop +#define MGL_ST_BREAK 8 // loop break +#define MGL_ST_STOP (MGL_ST_FALSE|MGL_ST_DONE|MGL_ST_BREAK) +#define MGL_ST_SKIP (MGL_ST_FALSE|MGL_ST_DONE) +struct mglPosStack +{ + int pos; ///< position to return + mglData v; ///< data to iterate + long ind; ///< index in data array + int par; ///< for-parameter + unsigned state; ///< state of stack item + mglPosStack(int st=MGL_ST_LOOP):pos(-1),ind(0),par(-1),state(st) {} }; //----------------------------------------------------------------------------- /// Function for asking question in console mode @@ -101,7 +112,8 @@ public: volatile bool Stop; ///< Stop command was. Flag prevent further execution mglCommand *Cmd; ///< Table of MGL commands (can be changed by user). It MUST be sorted by 'name'!!! long InUse; ///< Smart pointer (number of users) - const mglBase *curGr; ///< Current grapher + HMGL curGr; ///< Current grapher + int StarObhID; ///< staring object id mglParser(bool setsize=false); virtual ~mglParser(); @@ -135,7 +147,7 @@ public: /// Scan for functions (use NULL for reset) void ScanFunc(const wchar_t *line); /// Check if name is function and return its address (or 0 if no) - long IsFunc(const std::wstring &name, int *narg=0); + long IsFunc(const wchar_t *name, int *narg=0); /// Find variable or return 0 if absent mglDataA *FindVar(const char *name) MGL_FUNC_PURE; mglDataA *FindVar(const wchar_t *name) MGL_FUNC_PURE; @@ -152,7 +164,7 @@ public: void AddParam(int n, const char *str); void AddParam(int n, const wchar_t *str); /// Add new MGL command(s) (last command MUST HAVE name[0]=0 !!!) - void AddCommand(mglCommand *cmd, int num=0); + void AddCommand(const mglCommand *cmd); /// Restore Once flag inline void RestoreOnce() { Once = true; } /// Delete variable by its name @@ -160,23 +172,33 @@ public: void DeleteVar(const wchar_t *name); /// Delete all data variables void DeleteAll(); + /// Delete temporary data arrays + inline void DeleteTemp() + { for(size_t i=0;itemp) + { mglDataA *u=DataList[i]; DataList[i]=0; delete u; } } /// Set variant of argument(s) separated by '?' to be used inline void SetVariant(int var=0) { Variant = var<=0?0:var; } +protected: + static mglCommand *BaseCmd; ///< Base table of MGL commands. It MUST be sorted by 'name'!!! + static void FillBaseCmd(); ///< Fill BaseCmd at initialization stage + + ///< Test if condition is not-valid (n=1) or false (0) or true (1) + int TestCond(long m, const mglArg &a0, mglArg &a1, bool &cond) + { + int n = 1; + if(a0.type==2) { cond = a0.v!=0; n=0; } + else if(a0.type==0) + { n=0; cond = a0.d->FindAny((m>1 && a1.type==1) ? a1.s.s:"u"); } + return n; + } private: // long parlen; ///< Length of parameter strings - std::wstring par[40]; ///< Parameter for substituting instead of $1, ..., $9 + mglString par[40]; ///< Parameter for substituting instead of $1, ..., $9 bool Once; ///< Flag for command which should be executed only once bool Skip; ///< Flag that commands should be skiped (inside 'once' block) - int if_stack[40]; ///< Stack for if-else-endif commands - int if_pos; ///< position in if_stack + std::vector stack; ///< Stack of if|for|while commands std::vector func; ///< function names and position std::vector fn_stack; ///< function calls stack -// int fn_pos; ///< position in function stack - int if_for[40]; ///< position in if_stack for for-cycle start - mglData *fval; ///< Values for for-cycle. Note that nx - number of elements, ny - next element, nz - address (or string number) of first cycle command - int for_stack[40]; ///< The order of for-variables - int for_addr; ///< Flag for saving address in variable (for_addr-1) - bool for_br; ///< Break is switched on (skip all comands until 'next') unsigned Variant; ///< Select variant of argument(s) separated by '?' /// Parse command @@ -194,8 +216,10 @@ private: /// Parse $N arguments void PutArg(std::wstring &str, bool def); /// In skip mode - bool inline ifskip() { return (if_pos>0 && !(if_stack[if_pos-1]&1)); } - bool inline skip() { return (Skip || ifskip() || for_br); } + bool inline ifskip() + { return ( stack.size() && (stack.back().state & MGL_ST_SKIP) ); } + bool inline skip() + { return (Skip || (stack.size() && (stack.back().state & MGL_ST_STOP) )); } bool CheckForName(const std::wstring &s); // check if name is valid for new data }; //----------------------------------------------------------------------------- diff --git a/include/mgl2/pde.h b/include/mgl2/pde.h index d476569..6b59eb4 100644 --- a/include/mgl2/pde.h +++ b/include/mgl2/pde.h @@ -62,6 +62,8 @@ uintptr_t MGL_EXPORT mgl_qo3d_solve_(const char *ham, uintptr_t* ini_re, uintptr HMDT MGL_EXPORT mgl_ode_solve(void (*func)(const mreal *x, mreal *dx, void *par), int n, const mreal *x0, mreal dt, mreal tmax, void *par); /// Saves result of ODE solving for var variables with right part func (separated by ';') and initial conditions x0 over time interval [0,tmax] with time step dt HMDT MGL_EXPORT mgl_ode_solve_str(const char *func, const char *var, HCDT x0, mreal dt, mreal tmax); +/// Saves result of ODE solving for var complex variables with right part func (separated by ';') and initial conditions x0 over time interval [0,tmax] with time step dt +HADT MGL_EXPORT mgl_ode_solve_str_c(const char *func, const char *var, HCDT x0, mreal dt, mreal tmax); /// Saves result of ODE solving of n equations with right part func and initial conditions x0 over time interval [0,tmax] with time step dt. Function bord (if not NULL) is called each time step to apply border reflection. HMDT MGL_EXPORT mgl_ode_solve_ex(void (*func)(const mreal *x, mreal *dx, void *par), int n, const mreal *x0, mreal dt, mreal tmax, void *par, void (*bord)(mreal *x, const mreal *xp, void *par)); /// Finds ray with starting point r0, p0 (and prepares ray data for mgl_qo2d_solve) diff --git a/include/mgl2/prim.h b/include/mgl2/prim.h index 43abeaa..102a76c 100644 --- a/include/mgl2/prim.h +++ b/include/mgl2/prim.h @@ -148,6 +148,13 @@ void MGL_EXPORT mgl_puts_dir(HMGL graph, double x, double y, double z, double dx void MGL_EXPORT mgl_puts_dir_(uintptr_t *graph, mreal *x, mreal *y, mreal *z, mreal *dx, mreal *dy, mreal *dz, const char *text, const char *font, mreal *size, int, int); void MGL_EXPORT mgl_putsw_dir(HMGL graph, double x, double y, double z, double dx, double dy, double dz, const wchar_t *text, const char *font, double size); +/// Draw user-defined symbol in position p +void MGL_EXPORT mgl_symbol(HMGL gr, double x, double y, double z, char id, const char *how, double size); +void MGL_EXPORT mgl_symbol_(uintptr_t *gr, double *x, double *y, double *z, char *id, const char *how, double *size,int,int); +/// Draw user-defined symbol in position p along direction d +void MGL_EXPORT mgl_symbol_dir(HMGL gr, double x, double y, double z, double dx, double dy, double dz, char id, const char *how, double size); +void MGL_EXPORT mgl_symbol_dir_(uintptr_t *gr, double *x, double *y, double *z, double *dx, double *dy, double *dz, char *id, const char *how, double *size,int,int); + /// Draw textual marks with size r at points {x,y,z} void MGL_EXPORT mgl_textmark_xyzr(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT r, const char *text, const char *fnt, const char *opt); void MGL_EXPORT mgl_textmark_xyzr_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *r, const char *text, const char *fnt, const char *opt,int,int,int); @@ -237,6 +244,16 @@ void MGL_EXPORT mgl_bifurcation_str(HMGL gr, double dx, const char *f, const cha void MGL_EXPORT mgl_bifurcation_dat_(uintptr_t *gr, double *dx, uintptr_t *f, const char *stl, const char *opt, int,int); void MGL_EXPORT mgl_bifurcation_str_(uintptr_t *gr, double *dx, const char *f, const char *stl, const char *opt, int,int,int); +/// Draws Iris plots for determining cross-dependences of data arrays +/** NOTE: using the same ranges and empty ids will not draw axis. This will add data to existing Iris plot. + * Option value set the size of data labels ids, separated by ';'.*/ +void MGL_EXPORT mgl_iris(HMGL gr, HCDT dats, HCDT ranges, const char *ids, const char *stl, const char *opt); +void MGL_EXPORT mgl_iris_1(HMGL gr, HCDT dats, const char *ids, const char *stl, const char *opt); +void MGL_EXPORT mgl_irisw(HMGL gr, HCDT dats, HCDT ranges, const wchar_t *ids, const char *stl, const char *opt); +void MGL_EXPORT mgl_irisw_1(HMGL gr, HCDT dats, const wchar_t *ids, const char *stl, const char *opt); +void MGL_EXPORT mgl_iris_(uintptr_t *gr, uintptr_t *dats, uintptr_t *ranges, const char *ids, const char *stl, const char *opt,int l,int m,int n); +void MGL_EXPORT mgl_iris_1_(uintptr_t *gr, uintptr_t *dats, const char *ids, const char *stl, const char *opt,int,int,int); + #ifdef __cplusplus } #endif diff --git a/include/mgl2/qmathgl.h b/include/mgl2/qmathgl.h index de39072..228ddc5 100644 --- a/include/mgl2/qmathgl.h +++ b/include/mgl2/qmathgl.h @@ -65,7 +65,8 @@ public: inline mglDraw *getClass() { mglDraw *d=0; if(draw_func==mgl_draw_class) d = (mglDraw*)draw_par; - if(draw) d = draw; return d; } + if(draw) d = draw; + return d; } int getPer() const {return int(per);} ///< Get perspective value int getPhi() const {return int(phi);} ///< Get Phi-angle value @@ -205,7 +206,6 @@ protected: bool dotsRefr; ///< Set dots for image preview/rotation mreal x1,x2,y1,y2; ///< Zoom in region mreal ax1,ax2,ay1,ay2; ///< Axis range zoom - bool showMessage; ///< Flag for showing messages (enabled by each execute()) QMenu *popup; ///< Pointer to pop-up menu QTimer *timer; ///< Timer for animation QTimer *timerRefr; ///< Timer for redrawing @@ -228,7 +228,7 @@ class MGL_EXPORT mglDrawScript : public mglDraw public: HMPR par; ///< Parser to be used QString text; ///< Script to be drawn - long line; ///< Line which will be highlited + long line; ///< Line which will be highlighted mglDrawScript(HMPR p):mglDraw() { par=p; line=-1; } virtual ~mglDrawScript() {} int Draw(mglGraph *gr) diff --git a/include/mgl2/surf.h b/include/mgl2/surf.h index b290319..c828354 100644 --- a/include/mgl2/surf.h +++ b/include/mgl2/surf.h @@ -66,6 +66,15 @@ void MGL_EXPORT mgl_belt_xy_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintp void MGL_EXPORT mgl_belt(HMGL graph, HCDT z, const char *sch, const char *opt); void MGL_EXPORT mgl_belt_(uintptr_t *graph, uintptr_t *z, const char *sch, const char *opt,int,int); +/// Draw belts for 2d data specified parametrically with color proportional to c +/** Style 'x' draw belts in x-direction. */ +void MGL_EXPORT mgl_beltc_xy(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, const char *opt); +void MGL_EXPORT mgl_beltc_xy_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int,int); +/// Draw belts for 2d data with color proportional to c +/** Style 'x' draw belts in x-direction. */ +void MGL_EXPORT mgl_beltc(HMGL graph, HCDT z, HCDT c, const char *sch, const char *opt); +void MGL_EXPORT mgl_beltc_(uintptr_t *graph, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int,int); + /// Draw surface for 2d data specified parametrically with color proportional to z /** Style ‘#’ draw grid lines. Style ‘.’ produce plot by dots.*/ void MGL_EXPORT mgl_surf_xy(HMGL graph, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt); @@ -93,16 +102,22 @@ void MGL_EXPORT mgl_boxs_xy_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintp void MGL_EXPORT mgl_boxs(HMGL graph, HCDT z, const char *sch, const char *opt); void MGL_EXPORT mgl_boxs_(uintptr_t *graph, uintptr_t *z, const char *sch, const char *opt,int,int); +/// Draw vertical tiles with manual colors c for 2d data specified parametrically +void MGL_EXPORT mgl_tile_xyc(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, const char *opt); +void MGL_EXPORT mgl_tile_xyc_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int,int); /// Draw vertical tiles for 2d data specified parametrically void MGL_EXPORT mgl_tile_xy(HMGL graph, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt); -void MGL_EXPORT mgl_tile_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int,int); +void MGL_EXPORT mgl_tile_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *sch, const char *opt,int,int); /// Draw vertical tiles for 2d data void MGL_EXPORT mgl_tile(HMGL graph, HCDT z, const char *sch, const char *opt); void MGL_EXPORT mgl_tile_(uintptr_t *graph, uintptr_t *z, const char *sch, const char *opt,int,int); +/// Draw vertical tiles with variable size r and manual colors c for 2d data specified parametrically +void MGL_EXPORT mgl_tiles_xyc(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT r, HCDT c, const char *sch, const char *opt); +void MGL_EXPORT mgl_tiles_xyc_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *r, uintptr_t *c, const char *sch, const char *opt,int,int); /// Draw vertical tiles with variable size r for 2d data specified parametrically void MGL_EXPORT mgl_tiles_xy(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT r, const char *sch, const char *opt); -void MGL_EXPORT mgl_tiles_xy_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int,int); +void MGL_EXPORT mgl_tiles_xy_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *r, const char *sch, const char *opt,int,int); /// Draw vertical tiles with variable size r for 2d data void MGL_EXPORT mgl_tiles(HMGL graph, HCDT z, HCDT r, const char *sch, const char *opt); void MGL_EXPORT mgl_tiles_(uintptr_t *graph, uintptr_t *z, uintptr_t *r, const char *sch, const char *opt,int,int); diff --git a/include/mgl2/type.h b/include/mgl2/type.h index 6d639c0..7743169 100644 --- a/include/mgl2/type.h +++ b/include/mgl2/type.h @@ -42,9 +42,9 @@ struct MGL_EXPORT mglPoint mglPoint(mglPoint &&d):x(d.x),y(d.y),z(d.z),c(d.c) {} #endif inline void Set(mreal X=0,mreal Y=0,mreal Z=0,mreal C=0) {x=X;y=Y;z=Z;c=C;} - inline bool IsNAN() { return (x!=x || y!=y || z!=z || c!=c); } - inline mreal val(int i) { return (i<2 ? (i==0 ? x:y) : (i==2 ? z:c)); } - inline mreal norm() { return sqrt(x*x+y*y+z*z); } + inline bool IsNAN() const { return (x!=x || y!=y || z!=z || c!=c); } + inline mreal val(int i) const { mreal dat[4]={x,y,z,c}; return dat[i]; } + inline mreal norm() const { return sqrt(x*x+y*y+z*z); } inline void Normalize() { mreal v=norm(); x/=v; y/=v; z/=v; } inline const mglPoint &operator=(const mglPoint &p) @@ -64,9 +64,9 @@ inline mglPoint operator-(const mglPoint &a, const mglPoint &b) inline mglPoint operator-(const mglPoint &a) { return mglPoint(-a.x, -a.y, -a.z, -a.c); } inline mglPoint operator*(mreal b, const mglPoint &a) -{ return mglPoint(a.x*b, a.y*b, a.z*b); } +{ return mglPoint(a.x*b, a.y*b, a.z*b, a.c*b); } // TODO check conficts of a.c*b!!! inline mglPoint operator*(const mglPoint &a, mreal b) -{ return mglPoint(a.x*b, a.y*b, a.z*b); } +{ return mglPoint(a.x*b, a.y*b, a.z*b, a.c*b); } // TODO check conficts of a.c*b!!! inline mglPoint operator/(const mglPoint &a, mreal b) { return mglPoint(a.x/b, a.y/b, a.z/b); } inline mreal operator*(const mglPoint &a, const mglPoint &b) @@ -81,10 +81,10 @@ inline mglPoint operator^(const mglPoint &a, const mglPoint &b) { return mglPoint(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x); } inline mglPoint operator!(const mglPoint &a) { mreal f=mgl_hypot(a.x,a.y); return f==0?mglPoint(0.,1.,0.):mglPoint(-a.y/f, a.x/f, 0); } -inline bool operator==(const mglPoint &a, const mglPoint &b) +inline bool operator==(const mglPoint &a, const mglPoint &b) // NOTE: exact comparison is used here { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z)+(a.c-b.c)*(a.c-b.c)==0; } //{ return !memcmp(&a, &b, sizeof(mglPoint)); } -inline bool operator!=(const mglPoint &a, const mglPoint &b) +inline bool operator!=(const mglPoint &a, const mglPoint &b) // NOTE: exact comparison is used here { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z)+(a.c-b.c)*(a.c-b.c)!=0; } //{ return memcmp(&a, &b, sizeof(mglPoint)); } inline bool operator<(const mglPoint &a, const mglPoint &b) @@ -107,6 +107,8 @@ struct MGL_EXPORT mglColor /// Constructor for RGB components manualy mglColor(float R,float G,float B, float A=1):r(R),g(G),b(B),a(A) {} + /// Constructor for RGB components manualy + mglColor(const unsigned char *c, float A=1):r(c[0]/255.f),g(c[1]/255.f),b(c[3]/255.f),a(A) {} /// Constructor set default color mglColor():r(0),g(0),b(0),a(1) {} /// Constructor set color from character id @@ -121,18 +123,20 @@ struct MGL_EXPORT mglColor /// Set color as Red, Green, Blue values void Set(mglColor c, float bright=1) { - if(bright<0) bright=0; if(bright>2.f) bright=2.f; - r = bright<=1 ? c.r*bright : 1 - (1-c.r)*(2-bright); - g = bright<=1 ? c.g*bright : 1 - (1-c.g)*(2-bright); - b = bright<=1 ? c.b*bright : 1 - (1-c.b)*(2-bright); a = 1; + if(bright<0) bright=0; + if(bright>2.f) bright=2.f; + if(bright<=1) + { r=c.r*bright; g=c.g*bright; b=c.b*bright; a = 1; } + else + { r=1-(1-c.r)*(2-bright); g=1-(1-c.g)*(2-bright); b=1-(1-c.b)*(2-bright); a=1; } } /// Check if color is valid - inline bool Valid() - { return (r>=0 && r<=1 && g>=0 && g<=1 && b>=0 && b<=1 && a>=0 && a<=1); } + inline bool Valid() const + { return ((r>=0) & (r<=1) & (g>=0) & (g<=1) & (b>=0) & (b<=1) & (a>=0) & (a<=1)); } /// Get maximal spectral component - inline float Norm() + inline float Norm() const { return r>g ? r : (g>b ? g : b); } - inline float NormS() + inline float NormS() const { return r*r+g*g+b*b; } /// Set color from symbolic id inline void Set(char p, float bright=1) @@ -143,10 +147,10 @@ struct MGL_EXPORT mglColor inline const mglColor &operator=(const mglColor &p) { r=p.r; g=p.g; b=p.b; a=p.a; return p; } /// Copy color from other one - inline bool operator==(const mglColor &c) const + inline bool operator==(const mglColor &c) const // NOTE: exact comparison is used here { return (r-c.r)*(r-c.r)+(g-c.g)*(g-c.g)+(b-c.b)*(b-c.b)+(a-c.a)*(a-c.a)==0; } // { return !memcmp(this, &c, sizeof(mglColor)); } - inline bool operator!=(const mglColor &c) const + inline bool operator!=(const mglColor &c) const // NOTE: exact comparison is used here { return (r-c.r)*(r-c.r)+(g-c.g)*(g-c.g)+(b-c.b)*(b-c.b)+(a-c.a)*(a-c.a)!=0; } // { return memcmp(this, &c, sizeof(mglColor)); } inline bool operator<(const mglColor &c) const @@ -165,10 +169,160 @@ inline mglColor operator*(const mglColor &a, float b) { return mglColor(a.r*b, a.g*b, a.b*b, a.a*b); } inline mglColor operator*(float b, const mglColor &a) { return mglColor(a.r*b, a.g*b, a.b*b, a.a*b); } +inline float operator*(const mglColor &b, const mglColor &a) +{ return a.r*b.r+a.g*b.g+a.b*b.b; } inline mglColor operator/(const mglColor &a, float b) { return mglColor(a.r/b, a.g/b, a.b/b, a.a/b); } inline mglColor operator!(const mglColor &a) { return mglColor(1-a.r, 1-a.g, 1-a.b, a.a); } #endif //----------------------------------------------------------------------------- +#ifndef SWIG +/// Class for Unicode string. +/** NOTE: mglString accept multi-byte char* string for converting to wchar_t*. But it keep only single-byte char*!!! */ +struct MGL_EXPORT mglString +{ + char *s; + wchar_t *w; + mglString() { s=new char[1]; w=new wchar_t[1]; *s=*w=0; } + mglString(const mglString &str) + { + size_t ls = wcslen(str.w)+1; + s = new char[ls]; memcpy(s,str.s,ls); + w = new wchar_t[ls]; memcpy(w,str.w,ls*sizeof(wchar_t)); + } +#if MGL_HAVE_RVAL + mglString(mglString &&d):s(d.s),w(d.w) { d.s=NULL; d.w=NULL; } +#endif + mglString(const char *str) + { + if(str) + { + size_t ls=mbstowcs(0,str,0); + w = new wchar_t[ls+1]; mbstowcs(w,str,ls); w[ls]=0; + s = new char[ls+1]; for(size_t i=0;i<=ls;i++) s[i]=w[i]; + } + else { s=new char[1]; w=new wchar_t[1]; *s=*w=0; } + } + mglString(const wchar_t *str) + { + if(str) + { + size_t len=wcslen(str); + w = new wchar_t[len+1]; s = new char[len+1]; + for(size_t i=0;i<=len;i++) s[i]=w[i]=str[i]; + } + else { s=new char[1]; w=new wchar_t[1]; *s=*w=0; } + } + mglString(const std::string &str) + { + size_t ls=mbstowcs(0,str.c_str(),0); + w = new wchar_t[ls+1]; mbstowcs(w,str.c_str(),ls); w[ls]=0; + s = new char[ls+1]; for(size_t i=0;i<=ls;i++) s[i]=w[i]; + } + mglString(const std::wstring &str) + { + size_t len=str.length(); + w = new wchar_t[len+1]; s = new char[len+1]; + for(size_t i=0;i<=len;i++) s[i]=w[i]=str[i]; + } + ~mglString() { if(w) { delete []s; delete []w; } } + /// String length + size_t length() const + { return wcslen(w); } + /// Crop string (like std::string::substr()) + void crop(size_t pos, size_t len=size_t(-1)) + { + if(pos) for(size_t i=0;i &anim, std::string &dlg_ids, std::vector &dlg_par); +void MGL_EXPORT mgl_parse_animation(const char *text, std::vector &anim); //----------------------------------------------------------------------------- /// Class for drawing in windows (like, mglCanvasFL, mglCanvasQT and so on) /// Make inherited class and redefine Draw() function if you don't want to use function pointers. @@ -31,9 +33,10 @@ class MGL_EXPORT mglDraw public: virtual int Draw(mglGraph *)=0; ///< Function for drawing virtual void Reload(){} ///< Function for reloading data + virtual void Param(char id, const char *val){} ///< Function for setting parameter virtual void Click() {} ///< Callback function on mouse click #if MGL_HAVE_PTHR_WIDGET - mglDraw() { running=false; pthread_mutex_init(&mutex,NULL); } + mglDraw() { running=false; pthread_mutex_init(&mutex,NULL); thr=0; } virtual ~mglDraw() { pthread_mutex_destroy(&mutex); } virtual void Calc() {} ///< Function for calculations @@ -69,6 +72,8 @@ int MGL_EXPORT mgl_draw_graph(HMGL gr, void *p); int MGL_EXPORT mgl_draw_class(HMGL gr, void *p); void MGL_EXPORT mgl_click_class(void *p); void MGL_EXPORT mgl_reload_class(void *p); +void MGL_EXPORT mgl_prop_class(char id, const char *val, void *p); +void MGL_EXPORT mgl_prop_func(char id, const char *val, void *p); } //----------------------------------------------------------------------------- /// Abstract class for windows displaying graphics @@ -107,6 +112,21 @@ public: { mgl_wnd_animation(gr); } inline void SetClickFunc(void (*func)(void *p)) ///< Callback function for mouse click { mgl_set_click_func(gr,func); } + /// Set callback function for properties setup + void SetPropFunc(void (*prop)(char id, const char *val, void *p), void *par=NULL) + { mgl_wnd_set_prop(gr,prop,par); } + /// Make custom dialog for parameters ids of element properties defined by args + inline void MakeDialog(const char *ids, char const * const *args, const char *title) + { mgl_wnd_make_dialog(gr, ids, args, title); } + inline void MakeDialog(const std::string &ids, const std::vector &args, const char *title="") + { + if(args.size()>0) + { + std::vector buf; buf.reserve(args.size()); + for(size_t i=0;i #include "Backend.hpp" #include +#undef sprintf // fix libintl bug of defining sprintf //----------------------------------------------------------------------------- Backend::Backend(QObject *parent) : QObject(parent) { } //----------------------------------------------------------------------------- QString Backend::show(const QString& text) const { + static size_t counter=size_t(0xffffffff*mgl_rnd()); + char tmp[256]; + snprintf(tmp,256,"%s/mathgl%lu.json", P_tmpdir, counter); + tmp[255]=0; counter++; qDebug() << __FUNCTION__; - const char *tmp = tmpnam(0); wchar_t *wtext; mglGraph gr; gr.SetFaceNum(200); mglParse pr; pr.AllowSetSize(true); - setlocale(LC_CTYPE, ""); - setlocale(LC_NUMERIC, "C"); + setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); wtext = new wchar_t[text.size()+1]; text.toWCharArray(wtext); wtext[text.size()] = 0; @@ -42,8 +45,7 @@ QString Backend::coor(const QString& xy, const QString& text) const mglGraph gr; mglParse pr; pr.AllowSetSize(true); - setlocale(LC_CTYPE, ""); - setlocale(LC_NUMERIC, "C"); + setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); wtext = new wchar_t[text.size()+1]; text.toWCharArray(wtext); wtext[text.size()] = 0; @@ -63,7 +65,10 @@ QString Backend::coor(const QString& xy, const QString& text) const QString Backend::geometry(const QString& mgl) const { qDebug() << __FUNCTION__; - const char *tmp = tmpnam(0); + char tmp[256]; + static size_t counter=size_t(0xffffffff*mgl_rnd()); + snprintf(tmp,256,"%s/mathgl%lu.json", P_tmpdir, counter); + tmp[255]=0; counter++; wchar_t *wmgl; mglGraph gr; #if 0 @@ -71,8 +76,7 @@ QString Backend::geometry(const QString& mgl) const #endif mglParse pr; pr.AllowSetSize(true); - setlocale(LC_CTYPE, ""); - setlocale(LC_NUMERIC, "C"); + setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); wmgl = new wchar_t[mgl.size()+1]; mgl.toWCharArray(wmgl); wmgl[mgl.size()] = 0; diff --git a/json/CMakeLists.txt b/json/CMakeLists.txt index 63733a1..8e50149 100644 --- a/json/CMakeLists.txt +++ b/json/CMakeLists.txt @@ -1,19 +1,51 @@ +if(enable-qt5) + include(../scripts/qt5.cmake) + + find_qt5_libs(OFF ON Network) + if(TARGET Qt5::Network) + set(MGL_QT5_LIBS ${MGL_QT5_LIBS} Qt5::Network) + find_qt5_libs(OFF OFF WebKitWidgets WebEngineWidgets) + if(enable-json-sample-we) + if(TARGET Qt5::WebEngineWidgets) + set(MGL_QT5_LIBS ${MGL_QT5_LIBS} Qt5::WebEngineWidgets) + set(mgl_qt_def MGL_USE_QT5_WE) + else(TARGET Qt5::WebEngineWidgets) + message(STATUS "Couldn't find Qt5 WebEngineWidgets library. Trying WebKit.") + set(enable-json-sample-we OFF) + endif(TARGET Qt5::WebEngineWidgets) + endif(enable-json-sample-we) + if(TARGET Qt5::WebKitWidgets) + set(MGL_QT5_LIBS ${MGL_QT5_LIBS} Qt5::WebKitWidgets) + else(TARGET Qt5::WebKitWidgets) + message(STATUS "Couldn't find Qt5 WebKitWidgets library. JSON sample disabled.") + set(enable-json-sample OFF) + endif(TARGET Qt5::WebKitWidgets) + else(TARGET Qt5::Network) + message(STATUS "Couldn't find Qt5 Network library. JSON sample disabled.") + set(enable-json-sample OFF) + endif(TARGET Qt5::Network) +else(enable-qt5) + include(../scripts/qt4.cmake) + + foreach(mgl_qt4_lib ${MGL_QT4_LIBS_FIND_JSON}) + if(TARGET Qt4::${mgl_qt4_lib}) + set(MGL_QT4_LIBS ${MGL_QT4_LIBS} Qt4::${mgl_qt4_lib}) + else(TARGET Qt4::${mgl_qt4_lib}) + message(STATUS "Couldn't find Qt4 ${mgl_qt4_lib} library. JSON sample disabled.") + set(enable-json-sample OFF) + endif(TARGET Qt4::${mgl_qt4_lib}) + endforeach(mgl_qt4_lib) +endif(enable-qt5) + if(enable-json-sample) -set(json_src Backend.cpp MainWindow.cpp) +set(json_src Backend.cpp MainWindow.cpp MainWindow.ui) set(json_moc_hdr Backend.hpp MainWindow.hpp) -include_directories(${MathGL_BINARY_DIR}/json) -if(enable-qt5) - include(../cmake-qt5.txt) - qt5_wrap_ui(json_ui_src MainWindow.ui) -else(enable-qt5) - include(../cmake-qt4.txt) - qt4_wrap_ui(json_ui_src MainWindow.ui) -endif(enable-qt5) -add_executable(MglForJsTestBench ${json_src} ${json_moc_hdr} ${json_ui_src}) +include_directories(${MathGL2_BINARY_DIR}/json) +add_executable(MglForJsTestBench ${json_src} ${json_moc_hdr}) if(enable-qt5) - target_compile_definitions(MglForJsTestBench PUBLIC MGL_USE_QT5) + target_compile_definitions(MglForJsTestBench PUBLIC MGL_USE_QT5 ${mgl_qt_def}) target_link_libraries(MglForJsTestBench mgl-qt5 ${MGL_QT5_LIBS}) else(enable-qt5) target_link_libraries(MglForJsTestBench mgl-qt4 ${MGL_QT4_LIBS}) diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index d6b84c1..da245d2 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -43,7 +43,11 @@ if(enable-python) OUTPUT_VARIABLE MGL_PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE) set(SWIG_MODULE_mathgl_EXTRA_DEPS numpy.i ${src_imp_dep}) - SWIG_ADD_MODULE(mathgl python mathgl.i) + if(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(mathgl python mathgl.i) + else(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_LIBRARY(mathgl LANGUAGE python SOURCES mathgl.i) + endif(${CMAKE_VERSION} VERSION_LESS "3.8.0") SWIG_LINK_LIBRARIES(mathgl mgl ${PYTHON_LIBRARIES}) set_target_properties(_mathgl PROPERTIES BUILD_WITH_INSTALL_RPATH ON) add_custom_command(OUTPUT mathgl.pyc @@ -54,7 +58,7 @@ if(enable-python) ) add_custom_target(mgl_python_module ALL DEPENDS _mathgl mathgl.pyc) - install(FILES ${MathGL_BINARY_DIR}/lang/mathgl.py ${MathGL_BINARY_DIR}/lang/mathgl.pyc DESTINATION ${MGL_PYTHON_SITE_PACKAGES}) + install(FILES ${MathGL2_BINARY_DIR}/lang/mathgl.py ${MathGL2_BINARY_DIR}/lang/mathgl.pyc DESTINATION ${MGL_PYTHON_SITE_PACKAGES}) install (TARGETS _mathgl LIBRARY DESTINATION ${MGL_PYTHON_SITE_PACKAGES}) set(mgl_clean_files ${mgl_clean_files} mathgl.py) endif(enable-python) @@ -67,11 +71,15 @@ if(enable-lua) include_directories(${LUA_INCLUDE_DIR}) set(SWIG_MODULE_mgl-lua_EXTRA_DEPS numpy.i ${src_imp_dep}) - SWIG_ADD_MODULE(mgl-lua lua mathgl.i) + if(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(mgl-lua lua mathgl.i) + else(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_LIBRARY(mgl-lua LANGUAGE lua SOURCES mathgl.i) + endif(${CMAKE_VERSION} VERSION_LESS "3.8.0") SWIG_LINK_LIBRARIES(mgl-lua mgl ${LUA_LIBRARIES}) set_target_properties(mgl-lua PROPERTIES PREFIX "" BUILD_WITH_INSTALL_RPATH ON) - install (TARGETS mgl-lua LIBRARY DESTINATION ${MGL_LIB_INSTALL_DIR}) + install (TARGETS mgl-lua LIBRARY DESTINATION ${MathGL_INSTALL_LIB_DIR}) endif(enable-lua) if(enable-octave) @@ -105,19 +113,23 @@ if(enable-octave) message(STATUS "${oct_prog} ${oct_host} ${oct_api}") set(oct_arch ${oct_host}-${oct_api}) set(pkg_name mathgl) - set(mgl_pkg_dir ${MathGL_BINARY_DIR}/lang/${pkg_name}/inst/${oct_arch}) + set(mgl_pkg_dir ${MathGL2_BINARY_DIR}/lang/${pkg_name}/inst/${oct_arch}) add_compile_options(${oct_inc}) SET(SWIG_MODULE_mgl-oct_EXTRA_DEPS numpy.i ${src_imp_dep}) - SWIG_ADD_MODULE(mgl-oct octave mathgl.i) + if(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_MODULE(mgl-oct octave mathgl.i) + else(${CMAKE_VERSION} VERSION_LESS "3.8.0") + SWIG_ADD_LIBRARY(mgl-oct LANGUAGE octave SOURCES mathgl.i) + endif(${CMAKE_VERSION} VERSION_LESS "3.8.0") SWIG_LINK_LIBRARIES(mgl-oct mgl) set_target_properties(mgl-oct PROPERTIES OUTPUT_NAME mathgl PREFIX "" SUFFIX ".oct" BUILD_WITH_INSTALL_RPATH ON) add_custom_command(OUTPUT mathgl.tar.gz COMMAND ${CMAKE_COMMAND} -E make_directory ${mgl_pkg_dir} - COMMAND ${CMAKE_COMMAND} -E copy ${MathGL_SOURCE_DIR}/COPYING ${MathGL_BINARY_DIR}/lang/${pkg_name} - COMMAND ${CMAKE_COMMAND} -E copy ${MathGL_SOURCE_DIR}/lang/DESCRIPTION ${MathGL_BINARY_DIR}/lang/${pkg_name} - COMMAND ${CMAKE_COMMAND} -E copy ${MathGL_SOURCE_DIR}/lang/INDEX ${MathGL_BINARY_DIR}/lang/${pkg_name} - COMMAND ${CMAKE_COMMAND} -E copy ${MathGL_SOURCE_DIR}/lang/PKG_ADD_template ${MathGL_BINARY_DIR}/lang/${pkg_name} + COMMAND ${CMAKE_COMMAND} -E copy ${MathGL2_SOURCE_DIR}/COPYING ${MathGL2_BINARY_DIR}/lang/${pkg_name} + COMMAND ${CMAKE_COMMAND} -E copy ${MathGL2_SOURCE_DIR}/lang/DESCRIPTION ${MathGL2_BINARY_DIR}/lang/${pkg_name} + COMMAND ${CMAKE_COMMAND} -E copy ${MathGL2_SOURCE_DIR}/lang/INDEX ${MathGL2_BINARY_DIR}/lang/${pkg_name} + COMMAND ${CMAKE_COMMAND} -E copy ${MathGL2_SOURCE_DIR}/lang/PKG_ADD_template ${MathGL2_BINARY_DIR}/lang/${pkg_name} COMMAND ${CMAKE_COMMAND} -E copy $ ${mgl_pkg_dir} COMMAND ${oct_tar} cpzf mathgl.tar.gz ${pkg_name} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/lang diff --git a/lang/data.i b/lang/data.i index 9a18d50..6d289d5 100644 --- a/lang/data.i +++ b/lang/data.i @@ -27,7 +27,6 @@ public: long ny; ///< number of points in 2nd dimensions ('y' dimension) long nz; ///< number of points in 3d dimensions ('z' dimension) mreal *a; ///< data array - std::string id; ///< column (or slice) names bool link; ///< use external data (i.e. don't free it) /// Initiate by other mglData variable @@ -114,15 +113,18 @@ public: /// Crop the data inline void Crop(long n1, long n2,char dir='x') { mgl_data_crop(this,n1,n2,dir); } + /// Crop the data to be most optimal for FFT (i.e. to closest value of 2^n*3^m*5^l) + inline void Crop(const char *how="235x") + { mgl_data_crop_opt(this, how); } /// Insert data rows/columns/slices inline void Insert(char dir, long at=0, long num=1) { mgl_data_insert(this,dir,at,num); } /// Delete data rows/columns/slices inline void Delete(char dir, long at=0, long num=1) { mgl_data_delete(this,dir,at,num); } - /// Remove rows with duplicate values in column id - inline void Clean(long id) - { mgl_data_clean(this,id); } + /// Remove rows with duplicate values in column clmn + inline void Clean(long clmn) + { mgl_data_clean(this,clmn); } /// Join with another data array inline void Join(const mglData &d) { mgl_data_join(this,&d); } @@ -238,6 +240,13 @@ public: { return mglData(true,mgl_data_subdata_ext(this,&xx,&yy,0)); } inline mglData SubData(const mglData &xx) const { return mglData(true,mgl_data_subdata_ext(this,&xx,0,0)); } + /// Get data from sections ids, separated by value val along specified direction. + /** If section id is negative then reverse order is used (i.e. -1 give last section). */ + inline mglData Section(const mglData &ids, char dir='y', mreal val=NAN) const + { return mglData(true,mgl_data_section(this,&ids,dir,val)); } + inline mglData Section(long id, char dir='y', mreal val=NAN) const + { return mglData(true,mgl_data_section_val(this,id,dir,val)); } + /// Get trace of the data array inline mglData Trace() const { return mglData(true,mgl_data_trace(this)); } @@ -269,15 +278,23 @@ public: { return mglData(true,mgl_data_evaluate(this,&idat,&jdat,0,norm)); } inline mglData Evaluate(const mglData &idat, const mglData &jdat, const mglData &kdat, bool norm=true) const { return mglData(true,mgl_data_evaluate(this,&idat,&jdat,&kdat,norm)); } + /// Find roots for nonlinear equation defined by textual formula + inline mglData Roots(const char *eq, char var='x') const + { return mglData(true,mgl_data_roots(eq, this, var)); } /// Find roots for set of nonlinear equations defined by textual formula - inline mglData Roots(const char *func, char var='x') const - { return mglData(true,mgl_data_roots(func, this, var)); } + inline mglData MultiRoots(const char *eq, const char *vars) const + { return mglData(true,mgl_find_roots_txt(eq, vars, this)); } /// Find correlation with another data arrays inline mglData Correl(const mglData &dat, const char *dir) const { return mglData(true,mgl_data_correl(this,&dat,dir)); } /// Find auto correlation function inline mglData AutoCorrel(const char *dir) const { return mglData(true,mgl_data_correl(this,this,dir)); } + /// Get curves, separated by NAN, for maximal values of array d as function of x coordinate. + /** Noises below lvl amplitude are ignored. + * Parameter dy \in [0,ny] set the "attraction" distance of points to curve. */ + inline mglData Detect(mreal lvl, mreal dj, mreal di=0, mreal min_len=0) const + { return mglData(true,mgl_data_detect(this,lvl,dj,di,min_len)); } /// Cumulative summation the data in given direction or directions inline void CumSum(const char *dir) { mgl_data_cumsum(this,dir); } @@ -285,6 +302,9 @@ public: inline void Integral(const char *dir) { mgl_data_integral(this,dir); } /// Differentiate the data in given direction or directions inline void Diff(const char *dir) { mgl_data_diff(this,dir); } + /// Differentiate the parametrically specified data along direction v1 + inline void Diff(const mglData &v1) + { mgl_data_diff_par(this,&v1,0,0); } /// Differentiate the parametrically specified data along direction v1 with v2=const inline void Diff(const mglData &v1, const mglData &v2) { mgl_data_diff_par(this,&v1,&v2,0); } @@ -302,6 +322,12 @@ public: inline void Mirror(const char *dir) { mgl_data_mirror(this,dir); } /// Sort rows (or slices) by values of specified column inline void Sort(long idx, long idy=-1) { mgl_data_sort(this,idx,idy); } + /// Return dilated array of 0 or 1 for data values larger val + inline void Dilate(mreal val=1, long step=1) + { mgl_data_dilate(this, val, step); } + /// Return eroded array of 0 or 1 for data values larger val + inline void Erode(mreal val=1, long step=1) + { mgl_data_erode(this, val, step); } /// Set as the data envelop inline void Envelop(char dir='x') @@ -324,6 +350,12 @@ public: /// Normalize the data to range [v1,v2] slice by slice inline void NormSl(mreal v1=0,mreal v2=1,char dir='z',bool keep_en=true,bool sym=false) { mgl_data_norm_slice(this,v1,v2,dir,keep_en,sym); } + /// Limit the data to be inside [-v,v], keeping the original sign + inline void Limit(mreal v) + { mgl_data_limit(this, v); } + /// Project the periodical data to range [v1,v2] (like mod() function). Separate branches by NAN if sep=true. + inline void Coil(mreal v1, mreal v2, bool sep=true) + { mgl_data_coil(this, v1, v2, sep); } /// Apply Hankel transform inline void Hankel(const char *dir) { mgl_data_hankel(this,dir); } @@ -331,7 +363,12 @@ public: inline void SinFFT(const char *dir) { mgl_data_sinfft(this,dir); } /// Apply Cos-Fourier transform inline void CosFFT(const char *dir) { mgl_data_cosfft(this,dir); } - /// Fill data by 'x'/'k' samples for Hankel ('h') or Fourier ('f') transform + /// Fill data by coordinates/momenta samples for Hankel ('h') or Fourier ('f') transform + /** Parameter \a how may contain: + * ‘x‘,‘y‘,‘z‘ for direction (only one will be used), + * ‘k‘ for momenta samples, + * ‘h‘ for Hankel samples, + * ‘f‘ for Cartesian/Fourier samples (default). */ inline void FillSample(const char *how) { mgl_data_fill_sample(this,how); } /// Apply wavelet transform @@ -476,9 +513,19 @@ inline mglData mglQO3d(const char *ham, const mglData &ini_re, const mglData &in /// Finds ray with starting point r0, p0 (and prepares ray data for mglQO2d) inline mglData mglRay(const char *ham, mglPoint r0, mglPoint p0, mreal dt=0.1, mreal tmax=10) { return mglData(true, mgl_ray_trace(ham, r0.x, r0.y, r0.z, p0.x, p0.y, p0.z, dt, tmax)); } -/// Saves result of ODE solving (|u|^2) for "Hamiltonian" ham with initial conditions ini -inline mglData mglODE(const char *df, const char *var, const mglData &ini, mreal dt=0.1, mreal tmax=10) -{ return mglData(true, mgl_ode_solve_str(df,var, &ini, dt, tmax)); } +/// Saves result of ODE solving for var complex variables with right part func (separated by ';') and initial conditions x0 over time interval [0,tmax] with time step dt +inline mglData mglODE(const char *func, const char *var, const mglData &ini, mreal dt=0.1, mreal tmax=10) +{ return mglData(true, mgl_ode_solve_str(func,var, &ini, dt, tmax)); } +//----------------------------------------------------------------------------- +/// Get array as solution of tridiagonal system of equations a[i]*x[i-1]+b[i]*x[i]+c[i]*x[i+1]=d[i] +/** String \a how may contain: + * 'x', 'y', 'z' for solving along x-,y-,z-directions, or + * 'h' for solving along hexagonal direction at x-y plain (need nx=ny), + * 'c' for using periodical boundary conditions, + * 'd' for diffraction/diffuse calculation. */ +inline mglData mglTridMat(const mglData &A, const mglData &B, const mglData &C, const mglData &D, const char *how) +{ return mglData(true, mgl_data_tridmat(&A, &B, &C, &D, how)); } +//----------------------------------------------------------------------------- /// Calculate Jacobian determinant for D{x(u,v), y(u,v)} = dx/du*dy/dv-dx/dv*dy/du inline mglData mglJacobian(const mglData &x, const mglData &y) { return mglData(true, mgl_jacobian_2d(&x, &y)); } @@ -490,12 +537,27 @@ inline mglData mglTriangulation(const mglData &x, const mglData &y, const mglDat { return mglData(true,mgl_triangulation_3d(&x,&y,&z)); } inline mglData mglTriangulation(const mglData &x, const mglData &y) { return mglData(true,mgl_triangulation_2d(&x,&y)); } +/// Get curves, separated by NAN, for maximal values of array d as function of x coordinate. +/** Noises below lvl amplitude are ignored. + * Parameter dy \in [0,ny] set the "attraction" distance of points to curve. */ +inline mglData mglDetect(const mglData &d, mreal lvl, mreal dj, mreal di=0, mreal min_len=0) +{ return mglData(true,mgl_data_detect(&d, lvl, dj, di, min_len)); } +//----------------------------------------------------------------------------- /// Get array which is n-th pairs {x[i],y[i]} for iterated function system (fractal) generated by A inline mglData mglIFS2d(const mglData &A, long n, long skip=20) { return mglData(true,mgl_data_ifs_2d(&A,n,skip)); } /// Get array which is n-th points {x[i],y[i],z[i]} for iterated function system (fractal) generated by A inline mglData mglIFS3d(const mglData &A, long n, long skip=20) { return mglData(true,mgl_data_ifs_3d(&A,n,skip)); } +/// Get array which is n-th points {x[i],y[i],z[i]} for iterated function system (fractal) defined in *.ifs file 'fname' and named as 'name' +inline mglData mglIFSfile(const char *fname, const char *name, long n, long skip=20) +{ return mglData(true,mgl_data_ifs_file(fname,name,n,skip)); } +/// Get array which is n-th pairs {x[i],y[i]} for Flame fractal generated by A with functions F +/** NOTE: A.nx must be >= 7 and F.nx >= 2 and F.nz=A.ny. + * F[0,i,j] denote function id. F[1,i,j] give function weight, F(2:5,i,j) provide function parameters. + * Resulting point is {xnew,ynew} = sum_i F[1,i,j]*F[0,i,j]{IFS2d(A[j]){x,y}}. */ +inline mglData mglFlame2d(const mglData &A, const mglData &F, long n, long skip=20) +{ return mglData(true,mgl_data_flame_2d(&A,&F,n,skip)); } //----------------------------------------------------------------------------- /// Get sub-array of the data with given fixed indexes inline mglData mglSubData(const mglData &dat, long xx, long yy=-1, long zz=-1) diff --git a/lang/mathgl.i b/lang/mathgl.i index 3288af2..253ea07 100644 --- a/lang/mathgl.i +++ b/lang/mathgl.i @@ -40,6 +40,7 @@ #include "mgl2/type.h" #include "mgl2/data.h" #include "mgl2/mgl.h" +const double All = -1; const double Pi = M_PI; const double NaN = NAN; const double Inf = INFINITY; diff --git a/lang/mgl.i b/lang/mgl.i index 8fef535..48badd9 100644 --- a/lang/mgl.i +++ b/lang/mgl.i @@ -34,7 +34,7 @@ public: #else else if(kind==1) { gr=mgl_create_graph(width, height); - mglGlobalMess += "OpenGL support was disabled. Please, enable it and rebuild MathGL.\n"; } + SetGlobalWarn("OpenGL support was disabled. Please, enable it and rebuild MathGL."); } #endif else gr=mgl_create_graph(width, height); } @@ -58,6 +58,8 @@ public: /// Set the transparency on/off. inline void Alpha(bool enable) { mgl_set_alpha(gr, enable); } + /// Set the gray-scale mode on/off. + inline void Gray(bool enable) { mgl_set_gray(gr, enable); } /// Set default value of alpha-channel inline void SetAlphaDef(double alpha) { mgl_set_alpha_default(gr, alpha); } /// Set the transparency type (0 - usual, 1 - glass, 2 - lamp) @@ -105,11 +107,11 @@ public: inline void CutOff(const char *EqC) { mgl_set_cutoff(gr, EqC); } /// Set default font size - inline void SetFontSize(double size) { mgl_set_font_size(gr, size); } + inline void SetFontSize(double size) { mgl_set_font_size(gr, size); } /// Set default font style and color - inline void SetFontDef(const char *fnt) { mgl_set_font_def(gr, fnt); } + inline void SetFontDef(const char *fnt) { mgl_set_font_def(gr, fnt); } /// Set FontSize by size in pt and picture DPI (default is 16 pt for dpi=72) - virtual void SetFontSizePT(double pt, int dpi=72){ SetFontSize(pt*27.f/dpi); } + virtual void SetFontSizePT(double pt, int dpi=72) { SetFontSize(pt*27.f/dpi); } /// Set FontSize by size in centimeters and picture DPI (default is 0.56 cm = 16 pt) inline void SetFontSizeCM(double cm, int dpi=72) { SetFontSizePT(cm*28.45f,dpi); } /// Set FontSize by size in inch and picture DPI (default is 0.22 in = 16 pt) @@ -122,9 +124,14 @@ public: /// Restore font (load default font for new HMGL objects) inline void RestoreFont() { mgl_restore_font(gr); } /// Set to use or not text rotation - inline void SetRotatedText(bool rotated) { mgl_set_rotated_text(gr, rotated); } + inline void SetRotatedText(bool enable) { mgl_set_rotated_text(gr, enable); } + /// Set to scale text in relative subplots too + inline void SetScaleText(bool enable) { mgl_set_scale_text(gr, enable); } /// Set default font for all new HMGL and mglGraph objects static inline void SetDefFont(const char *name, const char *path="") { mgl_def_font(name,path); } + /// Add user-defined glyph for symbol and set its optional id + inline void DefineSymbol(char id, const mglData &x, const mglData &y) + { mgl_define_symbol(gr, id, &x, &y); } /// Set default palette inline void SetPalette(const char *colors) { mgl_set_palette(gr, colors); } @@ -154,6 +161,8 @@ public: static inline void SuppressWarn(bool on) { mgl_suppress_warn(on); } /// Check if MathGL version is valid (return false) or not (return true) static inline bool CheckVersion(const char *ver) { return mgl_check_version(ver); } + /// Display progress of something. + inline void Progress(int value, int maximal) { mgl_progress(value, maximal, gr); } /// Set axis range scaling -- simplified way to shift/zoom axis range -- need to replot whole image! inline void ZoomAxis(mglPoint p1=mglPoint(0,0,0,0), mglPoint p2=mglPoint(1,1,1,1)) @@ -261,6 +270,9 @@ public: /// Set to draw tick labels at axis origin inline void SetOriginTick(bool enable=true) { mgl_set_flag(gr,!enable, MGL_NO_ORIGIN); } + /// Set bit-value flag of HMGL state (for advanced users only) + inline void SetFlagAdv(int val, uint32_t flag) + { mgl_set_flag(gr, val, flag); } /// Put further plotting in m-th cell of nx*ny grid of the image. /** String \a style may contain: @@ -271,15 +283,15 @@ public: * '#' for using whole region. */ inline void SubPlot(int nx,int ny,int m,const char *style="<>_^", double dx=0, double dy=0) { mgl_subplot_d(gr, nx, ny, m, style, dx, dy); } - /// Put further plotting in rectangle of dx*dy cells starting from m-th cell of nx*ny grid of the image. + /// Put further plotting in rectangle of dx*dy cells starting from m-th cell of nx*ny grid of the image and shift it by distance {sx,sy}. /** String \a style may contain: * '<' for reserving space at left * '>' for reserving space at right * '^' for reserving space at top * '_' for reserving space at bottom * '#' for using whole region. */ - inline void MultiPlot(int nx,int ny,int m, int dx, int dy, const char *style="<>_^") - { mgl_multiplot(gr, nx, ny, m, dx, dy, style); } + inline void MultiPlot(int nx,int ny,int m, int dx, int dy, const char *style="<>_^", double sx=0, double sy=0) + { mgl_multiplot_d(gr, nx, ny, m, dx, dy, style, sx, sy); } /// Put further plotting in a region [x1,x2]*[y1,y2] of the image or subplot (x1,x2,y1,y2 in range [0, 1]). inline void InPlot(double x1,double x2,double y1,double y2, bool rel=true) { if(rel) mgl_relplot(gr, x1, x2, y1, y2); @@ -293,6 +305,9 @@ public: /// Put further plotting in cell of stick rotated on angles tet, phi inline void StickPlot(int num, int i, double tet, double phi) { mgl_stickplot(gr,num,i,tet,phi); } + /// Put further plotting in cell of stick sheared on sx, sy. + inline void ShearPlot(int num, int i, mreal sx, mreal sy, mreal xd=1, mreal yd=0) + { mgl_shearplot(gr,num,i,sx,sy,xd,yd); } /// Set factor of plot size inline void SetPlotFactor(double val) @@ -313,6 +328,9 @@ public: /// Set aspect ratio for further plotting. inline void Aspect(double Ax,double Ay,double Az=1) { mgl_aspect(gr, Ax, Ay, Az); } + /// Shear a further plotting. + inline void Shear(double Sx,double Sy) + { mgl_shear(gr, Sx, Sy); } /// Rotate a further plotting. inline void Rotate(double TetX,double TetZ=0,double TetY=0) { mgl_rotate(gr, TetX, TetZ, TetY); } @@ -350,11 +368,16 @@ public: /// Set drawing region for Quality&4 inline void SetDrawReg(long nx=1, long ny=1, long m=0) { mgl_set_draw_reg(gr,nx,ny,m); } /// Start group of objects - inline void StartGroup(const char *name) { mgl_start_group(gr, name); } + inline void StartGroup(const char *name) { mgl_start_group(gr, name); } /// End group of objects inline void EndGroup() { mgl_end_group(gr); } /// Highlight objects with given id inline void Highlight(int id) { mgl_highlight(gr, id); } + /// Set boundary box for export graphics into 2D file formats. + /** If x2<0 (y2<0) then full width (height) will be used. + * If x1<0 or y1<0 or x1>=x2|Width or y1>=y2|Height then cropping will be disabled. */ + inline void SetBBox(int x1=0, int y1=0, int x2=-1, int y2=-1) + { mgl_set_bbox(gr,x1,y1,x2,y2); } /// Show current image inline void ShowImage(const char *viewer, bool keep=0) @@ -577,6 +600,18 @@ public: inline void Bifurcation(double dx, const char *func, const char *stl="", const char *opt="") { mgl_bifurcation_str(gr,dx,func,stl,opt); } + /// Draws Iris plots for determining cross-dependences of data arrays + /** NOTE: using the same ranges and empty ids will not draw axis. This will add data to existing Iris plot. + * Option value set the size of data labels ids, separated by ';'.*/ + inline void Iris(mglData &dats, const char *ids, const char *stl="", const char *opt="") + { mgl_iris_1(gr,&dats,ids,stl,opt); } + inline void Iris(mglData &dats, const wchar_t *ids, const char *stl="", const char *opt="") + { mgl_irisw_1(gr,&dats,ids,stl,opt); } + inline void Iris(mglData &dats, mglData &ranges, const char *ids, const char *stl="", const char *opt="") + { mgl_iris(gr,&dats,&ranges,ids,stl,opt); } + inline void Iris(mglData &dats, mglData &ranges, const wchar_t *ids, const char *stl="", const char *opt="") + { mgl_irisw(gr,&dats,&ranges,ids,stl,opt); } + /// Draws the face between points with color stl (include interpolation up to 4 colors). inline void Face(mglPoint p1, mglPoint p2, mglPoint p3, mglPoint p4, const char *stl="r") { mgl_face(gr, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, p4.x, p4.y, p4.z, stl); } @@ -629,8 +664,8 @@ public: inline void Polygon(mglPoint p1, mglPoint p2, int n, const char *stl="r") { mgl_polygon(gr, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, n,stl); } /// Draws the arc around axis pr with center at p0 and starting from p1, by color stl and angle a (in degrees) - inline void Arc(mglPoint p0, mglPoint pr, mglPoint p1, double a, const char *stl="r") - { mgl_arc_ext(gr, p0.x,p0.y,p0.z, pr.x,pr.y,pr.z, p1.x,p1.y,p1.z, a,stl); } + inline void Arc(mglPoint p0, mglPoint pa, mglPoint p1, double a, const char *stl="r") + { mgl_arc_ext(gr, p0.x,p0.y,p0.z, pa.x,pa.y,pa.z, p1.x,p1.y,p1.z, a,stl); } /// Draws the arc around axis 'z' with center at p0 and starting from p1, by color stl and angle a (in degrees) inline void Arc(mglPoint p0, mglPoint p1, double a, const char *stl="r") { mgl_arc_ext(gr, p0.x,p0.y,p0.z, 0,0,1, p1.x,p1.y,p0.z, a,stl); } @@ -640,6 +675,12 @@ public: inline void Logo(const char *fname, bool smooth=false, const char *opt="") { mgl_logo_file(gr, fname, smooth, opt); } + /// Draw user-defined symbol in position p + inline void Symbol(mglPoint p, char id, const char *how="", double size=-1) + { mgl_symbol(gr, p.x, p.y, p.z, id, how, size); } + /// Draw user-defined symbol in position p along direction d + inline void Symbol(mglPoint p, mglPoint d, char id, const char *how="", double size=-1) + { mgl_symbol_dir(gr, p.x, p.y, p.z, d.x, d.y, d.z, id, how, size); } /// Print text in position p with specified font inline void Putsw(mglPoint p,const wchar_t *text,const char *font=":C",double size=-1) { mgl_putsw(gr, p.x, p.y, p.z, text, font, size); } @@ -1236,6 +1277,14 @@ public: /** Style 'x' draw belts in x-direction. */ inline void Belt(const mglData &z, const char *stl="", const char *opt="") { mgl_belt(gr, &z, stl, opt); } + /// Draw belts for 2d data specified parametrically with color proportional to c + /** Style 'x' draw belts in x-direction. */ + inline void BeltC(const mglData &x, const mglData &y, const mglData &z, const mglData &c, const char *stl="", const char *opt="") + { mgl_beltc_xy(gr, &x, &y, &z, &c, stl, opt); } + /// Draw belts for 2d data with color proportional to c + /** Style 'x' draw belts in x-direction. */ + inline void BeltC(const mglData &z, const mglData &c, const char *stl="", const char *opt="") + { mgl_beltc(gr, &z, &c, stl, opt); } /// Draw surface for 2d data specified parametrically with color proportional to z /** Style ‘#’ draw grid lines. Style ‘.’ produce plot by dots.*/ @@ -1253,12 +1302,16 @@ public: inline void Grid(const mglData &z, const char *stl="", const char *opt="") { mgl_grid(gr, &z, stl, opt); } + /// Draw vertical tiles with manual colors c for 2d data specified parametrically + inline void Tile(const mglData &x, const mglData &y, const mglData &z, const mglData &c, const char *stl="", const char *opt="") + { mgl_tile_xyc(gr, &x, &y, &z, &c, stl, opt); } /// Draw vertical tiles for 2d data specified parametrically inline void Tile(const mglData &x, const mglData &y, const mglData &z, const char *stl="", const char *opt="") { mgl_tile_xy(gr, &x, &y, &z, stl, opt); } /// Draw vertical tiles for 2d data inline void Tile(const mglData &z, const char *stl="", const char *opt="") { mgl_tile(gr, &z, stl, opt); } + /// Draw density plot for 2d data specified parametrically /** Style ‘#’ draw grid lines. Style ‘.’ produce plot by dots.*/ inline void Dens(const mglData &x, const mglData &y, const mglData &c, const char *stl="", const char *opt="") @@ -1277,6 +1330,17 @@ public: inline void Boxs(const mglData &z, const char *stl="", const char *opt="") { mgl_boxs(gr, &z, stl, opt); } + /// Draw contour lines on parametric surface at manual levels for 2d data specified parametrically + /** Style ‘f’ to draw solid contours. + * Style 't'/'T' draw contour labels below/above contours.*/ + inline void ContP(const mglData &v, const mglData &x, const mglData &y, const mglData &z, const mglData &a, const char *sch="", const char *opt="") + { mgl_contp_val(gr, &v, &x, &y, &z, &a, sch, opt); } + /// Draw contour lines on parametric surface at manual levels for 2d data specified parametrically + /** Style ‘f’ to draw solid contours. + * Style ‘t’/‘T’ draw contour labels below/above contours. + * Option "value" set the number of contour levels (default is 7). */ + inline void ContP(const mglData &x, const mglData &y, const mglData &z, const mglData &a, const char *sch="", const char *opt="") + { mgl_contp(gr, &x, &y, &z, &a, sch, opt); } /// Draw contour lines at manual levels for 2d data specified parametrically /** Style ‘_’ to draw contours at bottom of axis box. * Style 't'/'T' draw contour labels below/above contours.*/ @@ -1497,6 +1561,9 @@ public: inline void Beam(double val, const mglData &tr, const mglData &g1, const mglData &g2, const mglData &a, double r, const char *stl=NULL, int flag=0) { mgl_beam_val(gr,val,&tr,&g1,&g2,&a,r,stl,flag); } + /// Draw vertical tiles with variable size r and manual colors c for 2d data specified parametrically + inline void TileS(const mglData &x, const mglData &y, const mglData &z, const mglData &r, const mglData &c, const char *stl="", const char *opt="") + { mgl_tiles_xyc(gr, &x, &y, &z, &r, &c, stl, opt); } /// Draw vertical tiles with variable size r for 2d data specified parametrically inline void TileS(const mglData &x, const mglData &y, const mglData &z, const mglData &r, const char *stl="", const char *opt="") { mgl_tiles_xy(gr, &x, &y, &z, &r, stl, opt); } @@ -1742,6 +1809,22 @@ public: inline void FlowP(mglPoint p, const mglData &ax, const mglData &ay, const mglData &az, const char *sch="", const char *opt="") { mgl_flowp_3d(gr, p.x, p.y, p.z, &ax, &ay, &az, sch, opt); } + /// Plot flows from given plain for vector field {ax,ay,az} parametrically depended on coordinate {x,y,z} with color proportional to |a| + /** String \a sch may contain: + * color scheme: up-half (warm) corresponds to normal flow (like attractor), bottom-half (cold) corresponds to inverse flow (like source); + * 'v' for drawing arrows on the threads; + * 't' for drawing tapes of normals in x-y and y-z planes. + * Option "value" sets the number of threads (default is 5). */ + inline void Flow3(const mglData &x, const mglData &y, const mglData &z, const mglData &ax, const mglData &ay, const mglData &az, const char *sch="", double sVal=-1, const char *opt="") + { mgl_flow3_xyz(gr, &x, &y, &z, &ax, &ay, &az, sch, sVal, opt); } + /// Plot flows from given plain for vector field {ax,ay,az} with color proportional to |a| + /** String \a sch may contain: + * color scheme: up-half (warm) corresponds to normal flow (like attractor), bottom-half (cold) corresponds to inverse flow (like source); + * 'v' for drawing arrows on the threads; + * 't' for drawing tapes of normals in x-y and y-z planes. + * Option "value" sets the number of threads (default is 5). */ + inline void Flow3(const mglData &ax, const mglData &ay, const mglData &az, const char *sch="", double sVal=-1, const char *opt="") + { mgl_flow3(gr, &ax, &ay, &az, sch, sVal, opt); } /// Plot flows for gradient of scalar field phi parametrically depended on coordinate {x,y,z} /** String \a sch may contain: * color scheme: up-half (warm) corresponds to normal flow (like attractor), bottom-half (cold) corresponds to inverse flow (like source); @@ -2124,6 +2207,8 @@ public: class mglParse { HMPR pr; + mglParse &operator=(mglParse &p) + { pr = p.pr; mgl_use_parser(pr,1); return p; } public: mglParse(HMPR p) { pr = p; mgl_use_parser(pr,1); } mglParse(mglParse &p) { pr = p.pr; mgl_use_parser(pr,1); } @@ -2158,7 +2243,7 @@ public: /// Return description of MGL command inline const char *CmdDesc(const char *name) { return mgl_parser_cmd_desc(pr, name); } - /// Get name of command with nmber n + /// Get name of command with number n inline const char *GetCmdName(long n) { return mgl_parser_cmd_name(pr,n); } /// Get number of defined commands @@ -2172,6 +2257,9 @@ public: { mgl_rk_step(pr, eqs, vars, dt); } inline void RK_Step(const wchar_t *eqs, const wchar_t *vars, mreal dt=1) { mgl_rk_step_w(pr, eqs, vars, dt); } + // Open all data arrays from HDF file and assign it as variables of parser p + inline void OpenHDF(const char *fname) + { mgl_parser_openhdf(pr, fname); } /// Set value for parameter $N inline void AddParam(int id, const char *str) @@ -2188,6 +2276,12 @@ public: inline void AllowDllCall(bool allow) { mgl_parser_allow_dll_call(pr, allow); } /// Set flag to stop script parsing inline void Stop() { mgl_parser_stop(pr); } + /// Set variant of argument(s) separated by '?' to be used in further commands + inline void SetVariant(int var=0) + { mgl_parser_variant(pr, var); } + /// Set starting object ID + inline void StartID(int id=0) + { mgl_parser_start_id(pr, id); } /// Return result of formula evaluation inline mglData Calc(const char *formula) diff --git a/lang/type.i b/lang/type.i index 6704b2a..8f96bb9 100644 --- a/lang/type.i +++ b/lang/type.i @@ -24,6 +24,7 @@ typedef double mreal; typedef float mreal; #endif //----------------------------------------------------------------------------- +const mreal All = -1; const mreal Pi = M_PI; const mreal NaN = NAN; const mreal Inf = INFINITY; @@ -33,12 +34,15 @@ const mreal mgl_min_a = 1./256; struct mglPoint { mreal x,y,z,c; - mglPoint(mreal X=0,mreal Y=0,mreal Z=0,mreal C=0){x=X;y=Y;z=Z;c=C;} + mglPoint(mreal X=0,mreal Y=0,mreal Z=0,mreal C=0):x(X),y(Y),z(Z),c(C) {} + mglPoint(const mglPoint &d):x(d.x),y(d.y),z(d.z),c(d.c) {} inline bool IsNAN() { return (x!=x || y!=y || z!=z || c!=c); } inline mreal val(int i) { return (i<2 ? (i==0 ? x:y) : (i==2 ? z:c)); } inline mreal norm() { return sqrt(x*x+y*y+z*z); } inline void Normalize() { mreal v=norm(); x/=v; y/=v; z/=v; } + inline const mglPoint &operator=(const mglPoint &p) + { x=p.x; y=p.y; z=p.z; c=p.c; return p; } inline void operator+=(const mglPoint &a) { x+=a.x; y+=a.y; z+=a.z; c+=a.c; } inline void operator-=(const mglPoint &a) { x-=a.x; y-=a.y; z-=a.z; c-=a.c; } inline void operator+=(mreal a) { x+=a; y+=a; z+=a; } @@ -56,17 +60,22 @@ struct mglColor float a; ///< Alpha component of color /// Constructor for RGB components manualy - mglColor(float R,float G,float B, float A=1){ r=R; g=G; b=B; a=A; } + mglColor(float R,float G,float B, float A=1):r(R),g(G),b(B),a(A) {} + /// Constructor for RGB components manualy + mglColor(const unsigned char *c, float A=1):r(c[0]/255.f),g(c[1]/255.f),b(c[3]/255.f),a(A) {} /// Constructor set default color - mglColor() { r=g=b=0; a=1; } + mglColor():r(0),g(0),b(0),a(1) {} /// Constructor set color from character id mglColor(char c, float bright=1) { Set(c,bright); } + /// Copy constructor + mglColor(const mglColor &d):r(d.r),g(d.g),b(d.b),a(d.a) {} /// Set color as Red, Green, Blue values void Set(float R,float G,float B,float A=1) { r=R; g=G; b=B; a=A; } /// Set color as Red, Green, Blue values void Set(mglColor c, float bright=1) { - if(bright<0) bright=0; if(bright>2.f) bright=2.f; + if(bright<0) bright=0; + if(bright>2.f) bright=2.f; r = bright<=1 ? c.r*bright : 1 - (1-c.r)*(2-bright); g = bright<=1 ? c.g*bright : 1 - (1-c.g)*(2-bright); b = bright<=1 ? c.b*bright : 1 - (1-c.b)*(2-bright); a = 1; @@ -85,11 +94,15 @@ struct mglColor float rgb[3]; mgl_chrrgb(p,rgb); Set(mglColor(rgb[0],rgb[1],rgb[2]),bright); } + inline const mglColor &operator=(const mglColor &p) + { r=p.r; g=p.g; b=p.b; a=p.a; return p; } /// Copy color from other one - inline bool operator==(const mglColor &c) const - { return !memcmp(this, &c, sizeof(mglColor)); } - inline bool operator!=(const mglColor &c) const - { return memcmp(this, &c, sizeof(mglColor)); } + inline bool operator==(const mglColor &c) const // NOTE: exact comparison is used here + { return (r-c.r)*(r-c.r)+(g-c.g)*(g-c.g)+(b-c.b)*(b-c.b)+(a-c.a)*(a-c.a)==0; } +// { return !memcmp(this, &c, sizeof(mglColor)); } + inline bool operator!=(const mglColor &c) const // NOTE: exact comparison is used here + { return (r-c.r)*(r-c.r)+(g-c.g)*(g-c.g)+(b-c.b)*(b-c.b)+(a-c.a)*(a-c.a)!=0; } +// { return memcmp(this, &c, sizeof(mglColor)); } inline bool operator<(const mglColor &c) const { return memcmp(this, &c, sizeof(mglColor))<0; } // transparency still the same @@ -98,3 +111,4 @@ struct mglColor inline void operator-=(const mglColor &c) { r-=c.r; g-=c.g; b-=c.b; a-=c.a; } }; //----------------------------------------------------------------------------- + diff --git a/mathgl-2x.cbp b/mathgl-2x.cbp index 40ea8f6..0c49253 100644 --- a/mathgl-2x.cbp +++ b/mathgl-2x.cbp @@ -3,15 +3,18 @@