From 95944fcfeee35b1c23d8ba474890c04fa6585c22 Mon Sep 17 00:00:00 2001 From: Dimitrios Eftaxiopoulos Date: Tue, 11 Sep 2012 19:57:59 +0300 Subject: [PATCH] Imported Upstream version 2.0.3 --- .kdev4/mathgl-2x.kdev4 | 61 -- CMakeLists.txt | 112 ++- COPYING_LGPL | 165 ++++ ChangeLog.txt | 34 + emblem.mgl | 40 + examples/CMakeLists.txt | 40 +- examples/fltk_example.cpp | 15 +- examples/full_test.cpp | 238 +++-- examples/glut_example.cpp | 2 +- examples/qt_example.cpp | 15 +- examples/wnd_samples.cpp | 15 +- examples/wx_example.cpp | 5 +- include/config.h.in | 8 + include/mgl2/addon.h | 3 +- include/mgl2/base.h | 201 +++-- include/mgl2/base_cf.h | 53 +- include/mgl2/canvas.h | 162 ++-- include/mgl2/canvas_cf.h | 138 +-- include/mgl2/canvas_wnd.h | 9 +- include/mgl2/cont.h | 52 +- include/mgl2/data.h | 36 +- include/mgl2/data_cf.h | 132 +-- include/mgl2/define.h | 44 +- include/mgl2/eval.h | 1 - include/mgl2/fit.h | 57 +- include/mgl2/fltk.h | 24 +- include/mgl2/font.h | 1 - include/mgl2/glut.h | 2 +- include/mgl2/mgl.h | 236 ++--- include/mgl2/mgl_cf.h | 11 + include/mgl2/opengl.h | 8 +- include/mgl2/other.h | 118 +-- include/mgl2/parser.h | 37 +- include/mgl2/plot.h | 12 +- include/mgl2/prim.h | 72 +- include/mgl2/qt.h | 6 +- include/mgl2/type.h | 42 +- include/mgl2/vect.h | 86 +- include/mgl2/volume.h | 92 +- include/mgl2/window.h | 22 +- lang/CMakeLists.txt | 26 +- lang/install.m | 1 + lang/mgl.i.in | 17 +- mgllab/CMakeLists.txt | 4 +- mgllab/animate.cpp | 2 +- mgllab/data.cpp | 6 +- mgllab/editor.cpp | 23 +- mgllab/grid.cpp | 4 - mgllab/help.cpp | 3 - mgllab/main.cpp | 3 - mgllab/mathgl.cpp | 14 +- mgllab/setup.cpp | 4 +- mgllab/udav.h | 2 +- src/CMakeLists.txt | 65 +- src/addon.cpp | 6 +- src/axis.cpp | 158 ++-- src/base.cpp | 267 ++++-- src/base_cf.cpp | 80 +- src/canvas.cpp | 194 ++-- src/canvas_cf.cpp | 150 ++-- src/cont.cpp | 587 ++++++++----- src/crust.cpp | 176 +++- src/data.cpp | 192 ++-- src/data_io.cpp | 104 ++- src/data_new.cpp | 62 +- src/data_op.cpp | 26 - src/data_png.cpp | 31 +- src/eval.cpp | 50 +- src/evalc.cpp | 12 +- src/evalp.cpp | 14 +- src/exec.cpp | 43 +- src/export.cpp | 27 +- src/export_2d.cpp | 129 +-- src/export_3d.cpp | 32 +- src/fit.cpp | 116 ++- src/font.cpp | 32 +- src/opengl.cpp | 14 +- src/other.cpp | 910 +++++++++---------- src/parser.cpp | 71 +- src/pde.cpp | 6 +- src/pixel.cpp | 123 ++- src/plot.cpp | 615 +++++++------ src/prc.cpp | 265 ++++-- src/prc/oPRCFile.cc | 19 +- src/prc/oPRCFile.h | 25 +- src/prc/writePRC.h | 2 +- src/prim.cpp | 224 +++-- src/s_hull/COPYING.txt | 6 + src/s_hull/s_hull.C | 1598 --------------------------------- src/s_hull/s_hull.h | 159 ---- src/s_hull/s_hull_pro.cpp | 1676 +++++++++++++++++++++++++++++++++++ src/s_hull/s_hull_pro.h | 149 ++++ src/surf.cpp | 156 ++-- src/vect.cpp | 256 +++--- src/volume.cpp | 337 +++---- texinfo/CMakeLists.txt | 230 +++-- texinfo/concept_en.texi | 31 +- texinfo/concept_ru.texi | 234 +++-- texinfo/core_en.texi | 633 +++++++------- texinfo/core_ru.texi | 695 ++++++++------- texinfo/data_en.texi | 270 +++--- texinfo/data_ru.texi | 770 ++++++++-------- texinfo/doc_en.texi | 52 +- texinfo/doc_ru.texi | 56 +- texinfo/ex_mgl_en.texi | 90 +- texinfo/ex_mgl_ru.texi | 60 +- texinfo/example_en.texi | 365 +++++--- texinfo/example_ru.texi | 503 +++++++---- texinfo/index.html | 4 +- texinfo/mathgl_en.texi | 18 +- texinfo/mathgl_ru.texi | 15 +- texinfo/mgl_en.texi | 18 +- texinfo/mgl_ru.texi | 71 +- texinfo/other_en.texi | 132 +-- texinfo/other_ru.texi | 134 +-- texinfo/overview_en.texi | 16 +- texinfo/overview_ru.texi | 366 ++------ texinfo/parse_en.texi | 6 + texinfo/parse_ru.texi | 43 +- texinfo/png/Makefile.am | 11 - texinfo/png/hotdogs.pts | 1748 ------------------------------------- texinfo/title.html | 8 +- texinfo/toc_en.html | 6 +- texinfo/toc_fr.html | 2 +- texinfo/toc_ru.html | 2 +- texinfo/web_en.texi | 221 ++--- texinfo/web_fr.texi | 6 +- texinfo/web_ru.texi | 6 +- texinfo/widget_en.texi | 34 +- texinfo/widget_ru.texi | 462 ++++++---- todo.txt | 101 +++ udav/CMakeLists.txt | 7 + udav/UDAV.desktop | 12 + udav/anim_dlg.cpp | 2 +- udav/dat_pnl.cpp | 11 +- udav/help_pnl.cpp | 6 +- udav/hint_dlg.cpp | 5 +- udav/mem_pnl.cpp | 6 +- udav/mem_pnl.h | 3 +- udav/plot_pnl.cpp | 3 +- udav/plot_pnl.h | 1 + udav/text_pnl.cpp | 4 + udav/textedit.cpp | 3 +- udav/udav_wnd.cpp | 26 +- utils/mglconv.cpp | 10 +- utils/mglview.cpp | 3 - widgets/fltk.cpp | 18 +- widgets/glut.cpp | 9 +- widgets/qt.cpp | 11 +- widgets/window.cpp | 19 +- 150 files changed, 9769 insertions(+), 9489 deletions(-) delete mode 100644 .kdev4/mathgl-2x.kdev4 create mode 100644 COPYING_LGPL create mode 100644 emblem.mgl create mode 100644 lang/install.m delete mode 100644 src/data_op.cpp delete mode 100755 src/s_hull/s_hull.C delete mode 100644 src/s_hull/s_hull.h create mode 100644 src/s_hull/s_hull_pro.cpp create mode 100644 src/s_hull/s_hull_pro.h delete mode 100644 texinfo/png/Makefile.am delete mode 100644 texinfo/png/hotdogs.pts create mode 100644 todo.txt create mode 100755 udav/UDAV.desktop diff --git a/.kdev4/mathgl-2x.kdev4 b/.kdev4/mathgl-2x.kdev4 deleted file mode 100644 index 0cc27b3..0000000 --- a/.kdev4/mathgl-2x.kdev4 +++ /dev/null @@ -1,61 +0,0 @@ -[Buildset] -BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x12\x00m\x00a\x00t\x00h\x00g\x00l\x00-\x002\x00x) - -[CMake] -BuildDirs=/home/balakin/progr/sfnet/mathgl/mathgl-2x/build -CMakeDir=/usr/share/cmake-2.8/Modules -Current CMake Binary=file:///usr/bin/cmake -CurrentBuildDir=file:///home/balakin/progr/sfnet/mathgl/mathgl-2x/build -CurrentBuildType=Debug -CurrentInstallDir= -Extra Arguments= -ProjectRootRelative=./ - -[Launch] -Launch Configurations=Launch Configuration 0,Launch Configuration 1 - -[Launch][Launch Configuration 0] -Configured Launch Modes=execute -Configured Launchers=nativeAppLauncher -Name=fltk_example -Type=Native Application - -[Launch][Launch Configuration 0][Data] -Arguments=-test -Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x03\x00\x00\x00\x12\x00m\x00a\x00t\x00h\x00g\x00l\x00-\x002\x00x\x00\x00\x00\n\x00u\x00t\x00i\x00l\x00s\x00\x00\x00\x0e\x00m\x00g\x00l\x00c\x00o\x00n\x00v) -Dependency Action=Build -EnvironmentGroup=default -Executable=file:///home/balakin/progr/sfnet/mathgl/mathgl-2x/build/examples/mgl_fltk_example -External Terminal=konsole --noclose --workdir %workdir -e %exe -Project Target=mathgl-2x,utils,mglconv -Use External Terminal=false -Working Directory= -isExecutable=true - -[Launch][Launch Configuration 1] -Configured Launch Modes=execute -Configured Launchers=nativeAppLauncher -Name=udav -Type=Native Application - -[Launch][Launch Configuration 1][Data] -Arguments= -Debugger Shell= -Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00) -Dependency Action=Nothing -Display Demangle Names=true -Display Static Members=false -EnvironmentGroup=default -Executable=file:///home/balakin/progr/sfnet/mathgl/mathgl-2x/build/udav/udav -External Terminal=konsole --noclose --workdir %workdir -e %exe -GDB Path= -Project Target= -Remote GDB Config Script= -Remote GDB Run Script= -Remote GDB Shell Script= -Use External Terminal=false -Working Directory= -isExecutable=true - -[Project] -VersionControlSupport=kdevsubversion diff --git a/CMakeLists.txt b/CMakeLists.txt index 51c43c7..db2c551 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,22 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8) project( MathGL ) set(CMAKE_VERBOSE_MAKEFILE ON) set(MathGL_VERSION_MAJOR 2) set(MathGL_VERSION_MINOR 0) -option(enable-double "Enable double precision in MathGL library") +option(enable-double "Enable double precision in MathGL library" ON) +option(enable-simple "Slightly increase drawing speed but disable mglDataA class") +option(enable-mpi "Enable mpi") option(enable-all "Enable all features") option(enable-langall "Enable all language interfaces") option(enable-lgpl "Enable only LGPL part of MathGL" OFF) -option(enable-ltdl "Enable loading modules support") +# option(enable-ltdl "Enable loading modules support") option(enable-pthread "Enable POSIX threads support") option(enable-gsl "Enable gsl support") option(enable-jpeg "Enable jpeg support") +option(enable-png "Enable png support" ON) +option(enable-zlib "Enable zlib support" ON) #option(enable-u3d "Enable u3d support") option(enable-pdf "Enable pdf support") option(enable-gif "Enable gif support") @@ -30,21 +34,37 @@ option(enable-doc "Enable documentation building") include_directories( ${MathGL_SOURCE_DIR}/include ${MathGL_BINARY_DIR}/include) +if(NOT MSVC) + find_library(M_LIB m) + if(NOT M_LIB) + message(SEND_ERROR "${M_LIB}") + endif(NOT M_LIB) +else(NOT MSVC) + set(M_LIB) +endif(NOT MSVC) + if(enable-double) set(MGL_USE_DOUBLE 1) else(enable-double) set(MGL_USE_DOUBLE 0) endif(enable-double) -include(FindZLIB) -if(NOT ZLIB_FOUND) - message(SEND_ERROR "Couldn't find ZLIB library.") -endif(NOT ZLIB_FOUND) +if(enable-simple) + set(MGL_NO_DATA_A 1) +message(STATUS "Class mglDataA is switched off.") +else(enable-simple) + set(MGL_NO_DATA_A 0) +endif(enable-simple) -include(FindPNG) -if(NOT PNG_FOUND) - message(SEND_ERROR "Couldn't find PNG libraries.") -endif(NOT PNG_FOUND) +if(enable-mpi) + set(MGL_HAVE_MPI 1) + find_package(MPI REQUIRED) + set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS}) + set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS}) + include_directories(MPI_INCLUDE_PATH) +else(enable-mpi) + set(MGL_HAVE_MPI 0) +endif(enable-mpi) if((enable-all OR enable-gsl) AND (NOT enable-lgpl) ) set(MGL_HAVE_GSL 1) @@ -61,18 +81,18 @@ else((enable-all OR enable-gsl) AND (NOT enable-lgpl) ) set(MGL_HAVE_GSL 0) endif((enable-all OR enable-gsl) AND (NOT enable-lgpl) ) -if(enable-all OR enable-ltdl) - set(MGL_HAVE_LTDL 1) - find_library(LTDL_LIB ltdl) - find_path(LTDL_INCLUDE_DIR ltdl.h) - if(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR) - message(SEND_ERROR "${LTDL_LIB}") - message(SEND_ERROR "${LTDL_INCLUDE_DIR}") - message(SEND_ERROR "Couldn't find LTDL library.") - endif(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR) -else(enable-all OR enable-ltdl) - set(MGL_HAVE_LTDL 0) -endif(enable-all OR enable-ltdl) +# if(enable-all OR enable-ltdl) +# set(MGL_HAVE_LTDL 1) +# find_library(LTDL_LIB ltdl) +# find_path(LTDL_INCLUDE_DIR ltdl.h) +# if(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR) +# message(SEND_ERROR "${LTDL_LIB}") +# message(SEND_ERROR "${LTDL_INCLUDE_DIR}") +# message(SEND_ERROR "Couldn't find LTDL library.") +# endif(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR) +# else(enable-all OR enable-ltdl) +# set(MGL_HAVE_LTDL 0) +# endif(enable-all OR enable-ltdl) if(enable-all OR enable-pthread) set(MGL_HAVE_PTHREAD 1) @@ -124,6 +144,31 @@ else(enable-all OR enable-jpeg) set(MGL_HAVE_JPEG 0) endif(enable-all OR enable-jpeg) + +if(enable-all OR enable-zlib) + set(MGL_HAVE_ZLIB 1) + include(FindZLIB) + if(NOT ZLIB_FOUND) + message(SEND_ERROR "Couldn't find ZLib library.") + endif(NOT ZLIB_FOUND) +else(enable-all OR enable-zlib) + set(MGL_HAVE_ZLIB 0) +endif(enable-all OR enable-zlib) + +if(enable-all OR enable-png) + set(MGL_HAVE_PNG 1) + if(NOT MGL_HAVE_ZLIB) + message(SEND_ERROR "You have to enable ZLib if you plan to use PNG export.") + endif(NOT MGL_HAVE_ZLIB) + include(FindPNG) + if(NOT PNG_FOUND) + message(SEND_ERROR "Couldn't find PNG library.") + endif(NOT PNG_FOUND) +else(enable-all OR enable-png) + set(MGL_HAVE_PNG 0) +endif(enable-all OR enable-png) + + # if(enable-u3d AND (NOT enable-lgpl) ) # set(MGL_HAVE_U3D 1) # find_library(U3D_LIB IDTF) @@ -142,13 +187,16 @@ endif(enable-all OR enable-jpeg) if((enable-all OR enable-pdf) AND (NOT enable-lgpl) ) set(MGL_HAVE_PDF 1) + if(NOT MGL_HAVE_PNG) + message(SEND_ERROR "You have to enable PNG if you plan to use PDF export.") + endif(NOT MGL_HAVE_PNG) find_library(HPDF_LIB hpdf) if(NOT HPDF_LIB) message(SEND_ERROR "Couldn't find libHaru.") endif(NOT HPDF_LIB) find_path(HPDF_INCLUDE_DIR hpdf_u3d.h) if(NOT HPDF_INCLUDE_DIR) - message(SEND_ERROR "Couldn't find headers of 3d-enabled version of libHaru.") + message(SEND_ERROR "Couldn't find headers of 3d-enabled version of libhpdf.") endif(NOT HPDF_INCLUDE_DIR) # message(STATUS "Found libHaru library at: ${HPDF_LIB}") # message(STATUS "Found libHaru headers: ${HPDF_INCLUDE_DIR}") @@ -239,6 +287,10 @@ if((enable-langall OR enable-octave) AND (NOT enable-lgpl) ) if(NOT oct_prog) message(SEND_ERROR "Couldn't find octave-config needed for octave interfaces compiling.") endif(NOT oct_prog) + find_program(oct_exec octave) + if(NOT oct_exec) + message(SEND_ERROR "Couldn't find octave needed for octave interfaces compiling.") + endif(NOT oct_exec) find_program(oct_mk mkoctfile) if(NOT oct_mk) message(SEND_ERROR "Couldn't find mkoctfile needed for octave interfaces compiling.") @@ -251,7 +303,7 @@ else((enable-langall OR enable-octave) AND (NOT enable-lgpl) ) set(MGL_HAVE_OCTAVE 0) endif((enable-langall OR enable-octave) AND (NOT enable-lgpl) ) -if(enable-all OR enable-doc) +if(enable-doc) set(MGL_HAVE_DOC 1) find_program(findmi makeinfo) if(NOT findmi) @@ -265,9 +317,9 @@ if(enable-all OR enable-doc) if(NOT findtp) message(SEND_ERROR "Couldn't find texi2pdf needed for documentation building.") endif(NOT findtp) -else(enable-all OR enable-doc) +else(enable-doc) set(MGL_HAVE_DOC 0) -endif(enable-all OR enable-doc) +endif(enable-doc) if(MGL_HAVE_PYTHON OR MGL_HAVE_OCTAVE) FIND_PACKAGE(SWIG) @@ -287,7 +339,6 @@ if(UNIX) endif(UNIX) if(WIN32) -# add_definitions(-DWIN32 -D_MSC_VER) add_definitions(-DWIN32) endif(WIN32) @@ -295,6 +346,7 @@ if(NOT WIN32) set(MGL_DATA_PATH "${CMAKE_INSTALL_PREFIX}/share/mathgl") set(MGL_DOC_PATH "${CMAKE_INSTALL_PREFIX}/share/doc/mathgl") set(MGL_MAN_PATH "${CMAKE_INSTALL_PREFIX}/share/man") +set(MGL_INFO_PATH "${CMAKE_INSTALL_PREFIX}/share/info") set(MGL_FONT_PATH "${MGL_DATA_PATH}/fonts") install(DIRECTORY fonts/ DESTINATION ${MGL_FONT_PATH} PATTERN ".svn" EXCLUDE @@ -303,10 +355,12 @@ endif(NOT WIN32) add_subdirectory( src ) add_subdirectory( widgets ) -add_subdirectory( utils ) add_subdirectory( include ) add_subdirectory( udav ) #add_subdirectory( mgllab ) add_subdirectory( lang ) +if(NOT MSVC) +add_subdirectory( utils ) add_subdirectory( examples ) add_subdirectory( texinfo ) +endif(NOT MSVC) diff --git a/COPYING_LGPL b/COPYING_LGPL new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/COPYING_LGPL @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/ChangeLog.txt b/ChangeLog.txt index fc4745f..05243db 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1 +1,35 @@ +2.0.3 Released 27 July 2012 + +* Make code compilable by compilers GNU/MinGW GCC, Clang, MS VisualStudio +* Add mglTriangulation() using s_hull_pro algorithm +* Add mglData::Grid() and mglGraph::DataGrid() for filling regular data by values of triangulated surface +* Add cmake options 'enable-png' and 'enable-zlib' +* Add SetTimeUTC() for using UTC time instead of local one +* Add SetTickShift() for additional shift of tick labels +* Add mglGraph::MPI_Send() and mglGraph::MPI_Recv() +* Vector plots now draw vector at edges, which are directed out of bounding box +* Add gap between 1d plots for avoiding possible undetermined overlapping. +* Add parallel build for documentation +* Bugfixes for memory leaks and uninitialized variables +* Bugfix for setting text size +* Bugfix for handling NAN color value +* Bugfix for missing lines in export to EPS/SVG + +2.0.2 Released 24 May 2012 + +* Add 'U' style for Axis() which disable ticks rotation. +* Bugfix for enable-opengl option. +* Bugfix for lighting. + +2.0.1 Released 23 May 2012 + +* Improve speed of drawing +* Add reading 3d data files using mglData::ReadMat() +* Exclude unnecessary dependencies/inclusions +* Improve build system + - Add multithreading + - Add install for Octave + - Separate enable-doc option from enable-all +* Minor bugfixes + 2.0 Released 12 April 2012 diff --git a/emblem.mgl b/emblem.mgl new file mode 100644 index 0000000..6c330c8 --- /dev/null +++ b/emblem.mgl @@ -0,0 +1,40 @@ +setsize 1000 500 +text 0.95 0.8 'MathGL' ':RiA' -4 +text 0.05 0.15 'library\n for scientific graphics' ':LiA' -2.5 +#rect 0.05 0.9 2 1.5 1.34 2 'w' +xtick -3:ytick -3:ztick -3 +subplot 1 1 0 '^_' + +stickplot 3 0 60 20:box +new y 50: fill y '-cos(pi*x-pi/4)' +new x 50: fill x '-sin(pi*x-pi/4)' +new z 50: fill z '2*x^2-1' + +area x y z 'lG' +plot x y z 'B2s' + +stickplot 3 1 60 20:box + +new aa 50 40 +modify aa '0.6*sin(2*pi*x)*sin(3*pi*y) + 0.4*cos(3*pi*(x*y))' +mirror aa 'y' +light on :alpha on +surf aa 'BbcyrR';alpha 0.8 +cont aa 'y' + +stickplot 3 2 60 20:box +rotate 0 20 + +new a 61 51 40 +modify a '-2*((2*x-1)^2 + (2*y-1)^2 + (2*z-1)^4 - (2*z-1)^2 - 0.1)' + +alpha on:light off +cloud a 'wyrRk' + +stop +cut 0 -1 -1 1 0 1.1 +surf3 a -1 'BbcyrR' +contf3 a 'x' -1 +contf3 a 'y' -1 +contf3 a 'z' 0 +contf3 a 'z' 39 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d50216a..f0c61f7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,37 +4,37 @@ endif(MGL_HAVE_GSL) add_executable(mgl_example wnd_samples.cpp full_test.cpp) target_link_libraries(mgl_example mgl) -install( - TARGETS mgl_example - RUNTIME DESTINATION bin -) +# install( +# TARGETS mgl_example +# RUNTIME DESTINATION bin +# ) if(MGL_HAVE_FLTK) add_executable(mgl_fltk_example wnd_samples.cpp fltk_example.cpp) target_link_libraries(mgl_fltk_example mgl-wnd) - install( - TARGETS mgl_fltk_example - RUNTIME DESTINATION bin - ) +# install( +# TARGETS mgl_fltk_example +# RUNTIME DESTINATION bin +# ) endif(MGL_HAVE_FLTK) if(MGL_HAVE_GLUT) add_executable(mgl_glut_example wnd_samples.cpp glut_example.cpp) target_link_libraries(mgl_glut_example mgl-glut) - install( - TARGETS mgl_glut_example - RUNTIME DESTINATION bin - ) +# install( +# TARGETS mgl_glut_example +# RUNTIME DESTINATION bin +# ) endif(MGL_HAVE_GLUT) if(MGL_HAVE_WX) include(${wxWidgets_USE_FILE}) add_executable(mgl_wx_example wnd_samples.cpp wx_example.cpp) target_link_libraries(mgl_wx_example ${wxWidgets_LIBRARIES} mgl-wnd) - install( - TARGETS mgl_wx_example - RUNTIME DESTINATION bin - ) +# install( +# TARGETS mgl_wx_example +# RUNTIME DESTINATION bin +# ) endif(MGL_HAVE_WX) if(MGL_HAVE_QT) @@ -42,8 +42,8 @@ if(MGL_HAVE_QT) qt_wrap_cpp(mgl_qt_example MGL_MOC_EX_FILES ../include/mgl2/qt.h) add_executable(mgl_qt_example wnd_samples.cpp qt_example.cpp ${MGL_MOC_EX_FILES}) target_link_libraries(mgl_qt_example mgl-wnd ${QT_LIBRARIES}) - install( - TARGETS mgl_qt_example - RUNTIME DESTINATION bin - ) +# install( +# TARGETS mgl_qt_example +# RUNTIME DESTINATION bin +# ) endif(MGL_HAVE_QT) diff --git a/examples/fltk_example.cpp b/examples/fltk_example.cpp index 0469d35..41cd32c 100644 --- a/examples/fltk_example.cpp +++ b/examples/fltk_example.cpp @@ -17,9 +17,10 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include "mgl2/mgl.h" -#include "mgl2/fltk.h" +#include "mgl2/window.h" +#if defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__) +#include +#endif //----------------------------------------------------------------------------- int test_wnd(mglGraph *gr); int sample(mglGraph *gr); @@ -28,7 +29,7 @@ int sample_2(mglGraph *gr); int sample_3(mglGraph *gr); int sample_d(mglGraph *gr); //----------------------------------------------------------------------------- -#include +//#include mglPoint pnt; // some global variable for changable data void *mgl_fltk_tmp(void *) { mgl_fltk_run(); return 0; } //#define PTHREAD_SAMPLE @@ -40,7 +41,7 @@ int main(int argc,char **argv) gr.RunThr(); for(int i=0;i<10;i++) // do calculation { -#ifdef WIN32 +#if defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__) Sleep(1000); #else sleep(1); // which can be very long @@ -56,14 +57,14 @@ int main(int argc,char **argv) #else mglWindow *gr; char key = 0; - if(argc>1 && argv[1][0]!='-') key = argv[1][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"); switch(key) { case '1': gr = new mglWindow(sample_1,"1D plots",0); break; case '2': gr = new mglWindow(sample_2,"2D plots",0); break; case '3': gr = new mglWindow(sample_3,"3D plots",0); break; - case 'd': gr = new mglWindow(sample_d,"Dual plots",0);break; + case 'd': gr = new mglWindow(sample_d,"Dual plots",0); break; case 't': gr = new mglWindow(test_wnd,"Testing",0); break; default: gr = new mglWindow(sample,"Drop and waves",0); break; } diff --git a/examples/full_test.cpp b/examples/full_test.cpp index 083569d..6b174c4 100644 --- a/examples/full_test.cpp +++ b/examples/full_test.cpp @@ -17,13 +17,11 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include #include -#include -#include -#include +#if !defined(_MSC_VER) && !defined(__BORLANDC__) #include +#endif #include #include "mgl2/mgl.h" #include "mgl2/eval.h" @@ -47,24 +45,84 @@ void smgl_combined(mglGraph *gr); void save(mglGraph *gr,const char *name,const char *suf); void test(mglGraph *gr) { - mglData y; mgls_prepare1d(&y); gr->SetOrigin(0,0,0); - if(!mini) { gr->SubPlot(2,2,0,""); gr->Title("Area plot (default)"); } - gr->Box(); gr->Area(y); - if(mini) return; - gr->SubPlot(2,2,1,""); gr->Title("2 colors"); gr->Box(); gr->Area(y,"cbgGyr"); - gr->SubPlot(2,2,2,""); gr->Title("'!' style"); gr->Box(); gr->Area(y,"!"); - gr->SubPlot(2,2,3); gr->Title("3d variant"); gr->Rotate(50,60); gr->Box(); - mglData yc(30), xc(30), z(30); z.Modify("2*x-1"); - yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)"); - gr->Area(xc,yc,z,"r"); + float itime =0, ltime=100; + + gr->MultiPlot(10,1,2, 8,1); + gr->SetTickLen(-.02); + gr->SetTickShift(mglPoint(0.2,0.2)); + gr->SetRanges((float) itime,(float) ltime,-3.,3); + gr->SetOrigin(NAN,NAN); + gr->SetTimeUTC(true); + + gr->SetTicksTime('x'); + gr->Axis("y", "b"); + gr->Axis("x"); + gr->SetOrigin(itime,3);gr->Axis("x_"); + gr->Label('y',"y_1",0); + gr->FPlot("2.5","k"); + gr->SetRanges((float) itime,(float) ltime,-10,10); + gr->SetOrigin(ltime,-10); // second axis + gr->Axis("y","r"); gr->Label('y',"#r{y_r}",0.2); + gr->FPlot("5.5","r"); + gr->SetRanges((float) itime,(float) ltime,-1,1); + gr->SetOrigin(itime-(ltime-itime)/7.,-1); // second axis + gr->Axis("y","b"); gr->Label('y',"#r{y_2}",0.2); + gr->FPlot("0.5","r"); + gr->SetRanges((float) itime,(float) ltime,-2,1); + gr->SetOrigin(itime-2*(ltime-itime)/7.,-2); // second axis + gr->Axis("y","b"); gr->Label('y',"#r{y_2}",0.2); + gr->FPlot("0.5","r"); + gr->SetRanges((float) itime,(float) ltime,-2,2); + gr->SetOrigin(itime-3*(ltime-itime)/7.,-2); // second axis + gr->Axis("y","r"); gr->Label('y',"#r{y_3}",0.2); + gr->FPlot("-1.5","r"); + gr->SetRanges((float) itime,(float) ltime,-20,20); + gr->SetOrigin(itime-4*(ltime-itime)/7.,-20); // second axis + gr->Axis("y","r"); gr->Label('y',"#r{y_3}",0.2); + gr->FPlot("-15","r"); + + gr->WriteJPEG("1.jpg"); + gr->WriteEPS("1.eps"); return; + + mglData ys(10), y; + ys.Modify("0.8*sin(pi*2*x)+0.2*rnd"); + mgls_prepare1d(&y); + + gr->SubPlot(2,2,0); + gr->SetOrigin(mglPoint(-1,-1,-1)); gr->Axis(); + gr->SetOrigin(mglPoint(1,1,1)); gr->Axis(); + gr->Box(); gr->Plot(ys," *"); gr->Label(ys,"y=%y"); + gr->Label('x',"x_y label"); gr->Label('y',"y_y label"); gr->Label('z',"z_y label"); + + gr->SubPlot(2,2,1); gr->Rotate(40,60); + gr->SetOrigin(mglPoint(-1,-1,-1)); gr->Axis(); + gr->SetOrigin(mglPoint(1,1,1)); gr->Axis(); + gr->SetOrigin(mglPoint(NAN,NAN,NAN)); gr->Axis(); + gr->Label('x',"x_y label"); gr->Label('y',"y_y label"); gr->Label('z',"z_y label"); - mglParse par; + gr->SubPlot(2,2,2); + gr->Box(); gr->Plot(y.SubData(-1,0)); + gr->Text(y,"This is very very long string drawn along a curve",":k"); + gr->Text(y,"Another string drawn above a curve","T:r"); + + gr->SubPlot(2,2,3); + mglPoint p; + gr->Mark(p,".r"); + gr->Puts(p,"A","@:C",-1); + gr->Puts(p,"A","@:C",-2); + + gr->SetRange('x',1341610306,1341612408); + gr->SetTicksTime('x'); + gr->Axis(); + return; + + /* mglParse par; par.AllowSetSize(true); setlocale(LC_CTYPE, ""); FILE *fp=fopen("/home/balakin/progr/sfnet/mathgl/mathgl-2x/examples/test.mgl","r"); par.Execute(gr,fp,true); - fclose(fp); + fclose(fp);*/ } //----------------------------------------------------------------------------- void fexport(mglGraph *gr) @@ -102,6 +160,23 @@ void fexport(mglGraph *gr) //----------------------------------------------------------------------------- // Sample functions (v.2.*0) //----------------------------------------------------------------------------- +const char *mmgl_triangulation="new x 100 '2*rnd-1':new y 100 '2*rnd-1':copy z x^2-y^2\n" +"new g 30 30:triangulate d x y\n" +"title 'Triangulation'\nrotate 50 60:box:light on\n" +"triplot d x y z:triplot d x y z '#k'\ndatagrid g x y z:mesh g 'm'\n"; +void smgl_triangulation(mglGraph *gr) // alpha and lighting +{ + mglData x(100), y(100), z(100); + gr->Fill(x,"2*rnd-1"); gr->Fill(y,"2*rnd-1"); gr->Fill(z,"v^2-w^2",x,y); + mglData d = mglTriangulation(x,y), g(30,30); + + if(!mini) gr->Title("Triangulation"); + gr->Rotate(40,60); gr->Box(); gr->Light(true); + gr->TriPlot(d,x,y,z); gr->TriPlot(d,x,y,z,"#k"); + + gr->DataGrid(g,x,y,z); gr->Mesh(g,"m"); +} +//----------------------------------------------------------------------------- const char *mmgl_alpha="subplot 2 2 0:title 'default':rotate 50 60:box\nsurf a\n" "subplot 2 2 0:title 'light on':rotate 50 60:box\nlight on:surf a\n" "subplot 2 2 0:title 'light on; alpha on':rotate 50 60:box\nalpha on:surf a\n" @@ -183,7 +258,7 @@ const char *mmgl_style=""; void smgl_style(mglGraph *gr) // pen styles { gr->SubPlot(2,2,0); - float d,x1,x2,x0,y=0.95; + 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"); @@ -221,7 +296,7 @@ void smgl_style(mglGraph *gr) // pen styles gr->Mark(mglPoint(x1,-5*d,0),"#>"); gr->Puts(mglPoint(x0,y-5*d),"'\\#>'",":rL"); gr->SubPlot(2,2,1); - float a=0.1,b=0.4,c=0.5; + 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"); @@ -304,7 +379,7 @@ void smgl_style(mglGraph *gr) // pen styles const char *mmgl_text="subplot 2 2 0 ''\ntext 0 1 'Text can be in ASCII and in Unicode'\ntext 0 0.6 'It can be \\wire{wire}, \\big{big} or #r{colored}'\n" "text 0 0.2 'One can change style in string: \\b{bold}, \\i{italic, \\b{both}}'\ntext 0 -0.2 'Easy to \\a{overline} or \\u{underline}'\n" "text 0 -0.6 'Easy to change indexes ^{up} _{down} @{center}'\ntext 0 -1 'It parse TeX: \\int \\alpha \\cdot '\n'\\sqrt3{sin(\\pi x)^2 + \\gamma_{i_k}} dx'\n" -"subplot0 2 2 1 ''\n text 0 0 '\\sqrt{\\frac{\\alpha^{\\gamma^2}+\\overset 1{\\big\\infty}}{\\sqrt3{2+b}}}' '@' -4\n" +"subplot0 2 2 1 ''\n text 0 0 '\\sqrt{\\frac{\\alpha^{\\gamma^2}+\\overset 1{\\big\\infty}}{\\sqrt3{2+b}}}' '@' -2\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' 'r:T'\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 0 -1 1 'rA':text -1 0 -1 1 'Vertical'\n"; @@ -323,7 +398,7 @@ void smgl_text(mglGraph *gr) // text drawing if(mini) return; gr->SubPlot(2,2,1,""); - gr->Puts(mglPoint(0,0.5), "\\sqrt{\\frac{\\alpha^{\\gamma^2}+\\overset 1{\\big\\infty}}{\\sqrt3{2+b}}}", "@", -4); + gr->Puts(mglPoint(0,0.5), "\\sqrt{\\frac{\\alpha^{\\gamma^2}+\\overset 1{\\big\\infty}}{\\sqrt3{2+b}}}", "@", -2); gr->Puts(mglPoint(0,-0.5),"Text can be printed\non several lines"); gr->SubPlot(2,2,2,""); @@ -343,7 +418,7 @@ const char *mmgl_fonts="loadfont 'bonum':text 0 1.1-2*d 'bonum font'\nloadfont ' "loadfont 'schola':text 0 1.1-8*d 'schola font'\nloadfont 'termes':text 0 1.1-9*d 'termes font'\nnloadfont ''\n"; void smgl_fonts(mglGraph *gr) // font typefaces { - float h=1.1, d=0.25; + double h=1.1, d=0.25; gr->LoadFont("STIX"); gr->Puts(mglPoint(0,h), "default font (STIX)"); gr->LoadFont("adventor"); gr->Puts(mglPoint(0,h-d), "adventor font"); gr->LoadFont("bonum"); gr->Puts(mglPoint(0,h-2*d), "bonum font"); @@ -507,7 +582,6 @@ const char *mmgl_type0="alpha on:light on:transptype 0:clf\nsubplot 2 2 0:rotate "subplot 2 2 3:rotate 50 60:axial a:box"; void smgl_type0(mglGraph *gr) // TranspType = 0 { - // if(type==5 || type==9 || type==10) return; gr->Alpha(true); gr->Light(true); mglData a; mgls_prepare2d(&a); gr->SetTranspType(0); gr->Clf(); @@ -522,7 +596,6 @@ const char *mmgl_type1="alpha on:light on:transptype 1:clf\nsubplot 2 2 0:rotate "subplot 2 2 3:rotate 50 60:axial a:box"; void smgl_type1(mglGraph *gr) // TranspType = 1 { - // if(type==5 || type==9 || type==10) return; gr->Alpha(true); gr->Light(true); mglData a; mgls_prepare2d(&a); gr->SetTranspType(1); gr->Clf(); @@ -537,7 +610,6 @@ const char *mmgl_type2="alpha on:light on:transptype 2:clf\nsubplot 2 2 0:rotate "subplot 2 2 3:rotate 50 60:axial a:box"; void smgl_type2(mglGraph *gr) // TranspType = 2 { - // if(type==5 || type==9 || type==10) return; gr->Alpha(true); gr->Light(true); mglData a; mgls_prepare2d(&a); gr->SetTranspType(2); gr->Clf(); @@ -639,7 +711,7 @@ void smgl_error(mglGraph *gr) { mglData y; mgls_prepare1d(&y); mglData x0(10), y0(10), ex0(10), ey0(10); - float x; + double x; for(int i=0;i<10;i++) { x = i/9.; @@ -1162,7 +1234,7 @@ const char *mmgl_parser="# NOT AVAILABLE\n"; void smgl_parser(mglGraph *gr) // example of MGL parsing { gr->Title("MGL parser sample"); - float a[100]; // let a_i = sin(4*pi*x), x=0...1 + 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); mglParse *parser = new mglParse; mglData *d = parser->AddVar("dat"); @@ -1265,7 +1337,7 @@ void smgl_fit(mglGraph *gr) // nonlinear fitting mglData rnd(100), in(100), res; gr->Fill(rnd,"0.4*rnd+0.1+sin(2*pi*x)"); gr->Fill(in,"0.3+sin(2*pi*x)"); - float ini[3] = {1,1,3}; + double ini[3] = {1,1,3}; mglData Ini(3,ini); res = gr->Fit(rnd, "a+b*sin(c*x)", "abc", Ini); if(!mini) gr->Title("Fitting sample"); @@ -1359,7 +1431,7 @@ void smgl_cones(mglGraph *gr) if(mini) return; gr->SubPlot(2,2,1); gr->Title("2 colors"); gr->Rotate(50,60); gr->Box(); gr->Cones(ys,"cbgGyr"); - gr->SubPlot(2,2,2); gr->Title("'#' style"); + gr->SubPlot(2,2,2); gr->Title("'\\#' style"); gr->Rotate(50,60); gr->Box(); gr->Cones(ys,"#"); gr->SubPlot(2,2,3); gr->Title("'a' style"); gr->SetRange('z',-2,2); // increase range since summation can exceed [-1,1] @@ -1489,7 +1561,7 @@ void smgl_ticks(mglGraph *gr) gr->SetTuneTicks(0); gr->Axis(); gr->SubPlot(3,2,2); gr->Title("Manual ticks"); gr->SetRanges(-M_PI,M_PI, 0, 2); - float val[]={-M_PI, -M_PI/2, 0, 0.886, M_PI/2, M_PI}; + 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"); gr->Axis(); gr->Grid(); gr->FPlot("2*cos(x^2)^2", "r2"); @@ -1560,7 +1632,7 @@ void smgl_hist(mglGraph *gr) gr->MultiPlot(3,3,3,2,2,""); gr->SetRanges(-1,1,-1,1,0,1); gr->Box(); gr->Dots(x,y,z,"wyrRk"); gr->MultiPlot(3,3,0,2,1,""); gr->SetRanges(-1,1,0,1); gr->Box(); gr->Bars(xx); gr->MultiPlot(3,3,5,1,2,""); gr->SetRanges(0,1,-1,1); gr->Box(); gr->Barh(yy); - gr->SubPlot(3,3,2); gr->Puts(mglPoint(0.5,0.5),"Hist and\nMultiPlot\nsample","a",-6); + gr->SubPlot(3,3,2); gr->Puts(mglPoint(0.5,0.5),"Hist and\nMultiPlot\nsample","a",-3); } //----------------------------------------------------------------------------- const char *mmgl_primitives=""; // TODO add later @@ -1671,16 +1743,16 @@ void smgl_dat_diff(mglGraph *gr) // differentiate mglData a(30,40); a.Modify("x*y"); gr->SubPlot(2,2,0); gr->Rotate(60,40); gr->Surf(a); gr->Box(); - gr->Puts(mglPoint(0.7,1,1.2),"a(x,y)"); + gr->Puts(mglPoint(0.7,1,1.2),"a(x,y)","",-2); gr->SubPlot(2,2,1); gr->Rotate(60,40); a.Diff("x"); gr->Surf(a); gr->Box(); - gr->Puts(mglPoint(0.7,1,1.2),"da/dx"); + gr->Puts(mglPoint(0.7,1,1.2),"da/dx","",-2); gr->SubPlot(2,2,2); gr->Rotate(60,40); a.Integral("xy"); gr->Surf(a); gr->Box(); - gr->Puts(mglPoint(0.7,1,1.2),"\\int da/dx dxdy"); + gr->Puts(mglPoint(0.7,1,1.2),"\\int da/dx dxdy","",-2); gr->SubPlot(2,2,3); gr->Rotate(60,40); a.Diff2("y"); gr->Surf(a); gr->Box(); - gr->Puts(mglPoint(0.7,1,1.2),"\\int {d^2}a/dxdy dx"); + gr->Puts(mglPoint(0.7,1,1.2),"\\int {d^2}a/dxdy dx","",-2); } //----------------------------------------------------------------------------- const char *mmgl_data_extra=""; // TODO add later @@ -1771,16 +1843,16 @@ const char *mmgl_triplot="list q 0 1 2 3 | 4 5 6 7 | 0 2 4 6 | 1 3 5 7 | 0 4 1 5 "triplot t xt yt zt 'b'\ntriplot t xt yt zt '#k'\n"; void smgl_triplot(mglGraph *gr) { - float q[] = {0,1,2,3, 4,5,6,7, 0,2,4,6, 1,3,5,7, 0,4,1,5, 2,6,3,7}; - float xc[] = {-1,1,-1,1,-1,1,-1,1}, yc[] = {-1,-1,1,1,-1,-1,1,1}, zc[] = {-1,-1,-1,-1,1,1,1,1}; + double q[] = {0,1,2,3, 4,5,6,7, 0,2,4,6, 1,3,5,7, 0,4,1,5, 2,6,3,7}; + double xc[] = {-1,1,-1,1,-1,1,-1,1}, yc[] = {-1,-1,1,1,-1,-1,1,1}, zc[] = {-1,-1,-1,-1,1,1,1,1}; mglData qq(6,4,q), xx(8,xc), yy(8,yc), zz(8,zc); gr->Light(true); //gr->Alpha(true); gr->SubPlot(2,1,0); gr->Title("QuadPlot sample"); gr->Rotate(50,60); gr->QuadPlot(qq,xx,yy,zz,"yr"); gr->QuadPlot(qq,xx,yy,zz,"k#"); - float t[] = {0,1,2, 0,1,3, 0,2,3, 1,2,3}; - float xt[] = {-1,1,0,0}, yt[] = {-1,-1,1,0}, zt[] = {-1,-1,-1,1}; + 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->SubPlot(2,1,1); gr->Title("TriPlot sample"); gr->Rotate(50,60); gr->TriPlot(tt,uu,vv,ww,"b"); @@ -1796,7 +1868,7 @@ void smgl_dots(mglGraph *gr) mglData x(n),y(n),z(n); for(i=0;iRotate(50,60); gr->Box(); gr->Dots(x,y,z); } //----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// Sample functions -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- /*void smgl_surf3_rgbd(mglGraph *gr) { mglData c; mgls_prepare3d(&c); @@ -1825,17 +1884,17 @@ void smgl_dots(mglGraph *gr) gr->Box(); gr->Surf3(c,"bgrd"); }*/ //----------------------------------------------------------------------------- +const char *mmgl_mirror="new a 30 40 '-pi*x*exp(-(y+1)^2-4*x^2)'\nalpha on:light on:rotate 40 60:box\n" +"surf a 'r';yrange 0 1\nsurf a 'b';yrange 0 -1\n"; void smgl_mirror(mglGraph *gr) // flag # { - gr->VertexColor(true); gr->TextureColor(false); // Let us use pre-lighting for this example - mglData a(30,40),x(30),y1(40),y2(40); - a.Modify("pi*(1-2*x)*exp(-4*y^2-4*(2*x-1)^2)"); - x.Fill(-1,1); y1.Fill(0,1); y2.Fill(0,-1); + mglData a(30,40); + gr->Fill(a,"-pi*x*exp(-(y+1)^2-4*x^2)"); + if(!mini) gr->Title("Example of options"); gr->Alpha(false); gr->Rotate(40,60); gr->Light(true); gr->Box(); - gr->Surf(x,y1,a,"r"); gr->Surf(x,y2,a,"b"); - gr->VertexColor(false); gr->TextureColor(true); // set settings back + gr->Surf(a,"r","yrange 0 1"); gr->Surf(a,"b","yrange 0 -1"); } //----------------------------------------------------------------------------- //============================================================================= @@ -1853,6 +1912,7 @@ int mgl_cmd_smp(const void *a, const void *b) return strcmp(aa->name, bb->name); } //----------------------------------------------------------------------------- +#if !defined(_MSC_VER) && !defined(__BORLANDC__) static struct option longopts[] = { { "test", no_argument, &dotest, 1 }, @@ -1885,28 +1945,30 @@ static struct option longopts[] = void usage() { puts ( - "-png - output png\n" - "-width=num - png picture width\n" - "-height=num - png picture height\n" - "-mini - png picture is 200x150\n" - "-big - png picture is 1920x1440\n" - "-idtf - output idtf\n" - "-u3d - output u3d\n" - "-pdf - output pdf\n" - "-eps - output EPS\n" - "-jpeg - output JPEG\n" - "-solid - output solid PNG\n" - "-svg - output SVG\n" - "-obj - output obj/mtl\n" - "-off - output off\n" - "-stl - output stl\n" - "-none - none output\n" - "-srnd - use the same random numbers in any run\n" - "-kind=name - produce only this picture" - "-thread=num - number of threads used" - "-test - perform test\n" + "--png - output png\n" + "--width=num - png picture width\n" + "--height=num - png picture height\n" + "--mini - png picture is 200x150\n" + "--big - png picture is 1920x1440\n" + "--idtf - output idtf\n" + "--u3d - output u3d\n" + "--pdf - output pdf\n" + "--eps - output EPS\n" + "--jpeg - output JPEG\n" + "--solid - output solid PNG\n" + "--svg - output SVG\n" + "--obj - output obj/mtl\n" + "--off - output off\n" + "--stl - output stl\n" + "--none - none output\n" + "--srnd - use the same random numbers in any run\n" + "--list - print list of sample names\n" + "--kind=name - produce only this sample\n" + "--thread=num - number of threads used\n" + "--test - perform test\n" ); -}; +} +#endif //----------------------------------------------------------------------------- void save(mglGraph *gr,const char *name,const char *suf="") { @@ -1969,14 +2031,17 @@ int main(int argc,char **argv) // mglGraphIDTF u3d; mglGraph *gr = NULL; mglSample *s=samp; +#if !defined(_MSC_VER) && !defined(__BORLANDC__) while(( ch = getopt_long_only(argc, argv, "", longopts, NULL)) != -1) switch(ch) { case 0: break; case 'w': width =atoi(optarg); break; case 'h': height=atoi(optarg); break; - case 'k': strcpy(name, optarg); tmp=strchr(name,'.'); - if(tmp) *tmp=0; break; + case 'k': strcpy(name, optarg); + tmp=strchr(name,'.'); if(tmp) *tmp=0; + tmp=strchr(name,'-'); if(tmp) *tmp=0; + break; case 't': mglNumThr=atoi(optarg); break; case 'l': while(s->name[0]) { printf("%s ",s->name); s++; } @@ -1984,13 +2049,13 @@ int main(int argc,char **argv) case '?': default: usage(); return 0; } +#endif - gr = new mglGraph; -// if(type==5 || type==9 || type==10) { u3d.unrotate_flag = true; gr = &u3d; } + gr = new mglGraph; //gr->SetQuality(0); - if(mini) { gr->SetSize(190,145); suf = "_sm"; } + if(mini) { gr->SetSize(190,145); suf = "-sm"; } else if(big) - { gr->SetSize(1920,1440); suf = "_lg"; } + { gr->SetSize(1920,1440); suf = "-lg"; } else gr->SetSize(width,height); if(dotest) @@ -2036,8 +2101,8 @@ mglSample samp[] = { {"barh", smgl_barh}, {"bars", smgl_bars}, {"belt", smgl_belt}, - {"boxplot", smgl_boxplot}, {"box", smgl_box}, + {"boxplot", smgl_boxplot}, {"boxs", smgl_boxs}, {"candle", smgl_candle}, {"chart", smgl_chart}, @@ -2111,6 +2176,7 @@ mglSample samp[] = { {"tiles", smgl_tiles}, {"torus", smgl_torus}, {"traj", smgl_traj}, + {"triangulation",smgl_triangulation}, {"triplot", smgl_triplot}, {"tube", smgl_tube}, {"type0", smgl_type0}, diff --git a/examples/glut_example.cpp b/examples/glut_example.cpp index 91a54b7..4d758be 100644 --- a/examples/glut_example.cpp +++ b/examples/glut_example.cpp @@ -17,7 +17,6 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include "mgl2/glut.h" //----------------------------------------------------------------------------- int test_wnd(mglGraph *gr); @@ -27,6 +26,7 @@ int sample_2(mglGraph *gr); int sample_3(mglGraph *gr); int sample_d(mglGraph *gr); //----------------------------------------------------------------------------- +typedef int (*draw_func)(mglGraph *gr); int main(int argc,char **argv) { char key = 0; diff --git a/examples/qt_example.cpp b/examples/qt_example.cpp index fa0dcf7..4a16d08 100644 --- a/examples/qt_example.cpp +++ b/examples/qt_example.cpp @@ -17,8 +17,10 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include "mgl2/window.h" +#if defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__) +#include +#endif //----------------------------------------------------------------------------- int test_wnd(mglGraph *gr); int sample(mglGraph *gr); @@ -27,8 +29,10 @@ int sample_2(mglGraph *gr); int sample_3(mglGraph *gr); int sample_d(mglGraph *gr); //----------------------------------------------------------------------------- +//#define PTHREAD_SAMPLE +#ifdef PTHREAD_SAMPLE #include -#include +#endif mglPoint pnt; // some global variable for changable data void *mgl_qt_tmp(void *); //----------------------------------------------------------------------------- @@ -45,7 +49,7 @@ void Foo::Calc() { for(int i=0;i<30;i++) // do calculation { -#ifdef WIN32 +#if defined(WIN32) || defined(_MSC_VER) || defined(__BORLANDC__) Sleep(1000); #else sleep(1); // which can be very long @@ -62,7 +66,6 @@ int Foo::Draw(mglGraph *gr) return 0; } //----------------------------------------------------- -//#define PTHREAD_SAMPLE int main(int argc,char **argv) { #ifdef PTHREAD_SAMPLE @@ -72,14 +75,14 @@ int main(int argc,char **argv) #else mglWindow *gr; char key = 0; - if(argc>1 && argv[1][0]!='-') key = argv[1][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"); switch(key) { case '1': gr = new mglWindow(sample_1,"1D plots",1); break; case '2': gr = new mglWindow(sample_2,"2D plots",1); break; case '3': gr = new mglWindow(sample_3,"3D plots",1); break; - case 'd': gr = new mglWindow(sample_d,"Dual plots",1);break; + case 'd': gr = new mglWindow(sample_d,"Dual plots",1); break; case 't': gr = new mglWindow(test_wnd,"Testing",1); break; default: gr = new mglWindow(sample,"Drop and waves",1); break; } diff --git a/examples/wnd_samples.cpp b/examples/wnd_samples.cpp index be1c4ae..92b160c 100644 --- a/examples/wnd_samples.cpp +++ b/examples/wnd_samples.cpp @@ -17,10 +17,6 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include -#include -#include //----------------------------------------------------------------------------- #include "mgl2/mgl.h" #include "mgl2/parser.h" @@ -34,6 +30,7 @@ void mgls_prepare3v(mglData *ex, mglData *ey, mglData *ez); int test_wnd(mglGraph *gr) { mgl_set_test_mode(true); + gr->SetQuality(6); gr->Box(); return 0; } @@ -415,7 +412,7 @@ void mgls_prepare1d(mglData *y, mglData *y1, mglData *y2, mglData *x1, mglData * if(y) y->Create(n,3); if(x1) x1->Create(n); if(x2) x2->Create(n); if(y1) y1->Create(n); if(y2) y2->Create(n); - float xx; + double xx; for(i=0;iCreate(n,m); if(b) b->Create(n,m); if(v) { v->Create(9); v->Fill(-1,1); } - float x,y; + double x,y; for(i=0;iCreate(n,m,l); if(b) b->Create(n,m,l); - float x,y,z; + double x,y,z; for(i=0;iCreate(n,m); if(b) b->Create(n,m); - float x,y; + double x,y; for(i=0;iCreate(n,n,n); ey->Create(n,n,n); ez->Create(n,n,n); - float x,y,z, r1,r2; + double x,y,z, r1,r2; for(i=0;i #include "mgl2/wx.h" //----------------------------------------------------------------------------- #ifdef ENABLE_MGLGRAPHWX @@ -28,8 +27,10 @@ int sample_2(mglGraph *gr, void *); int sample_3(mglGraph *gr, void *); int sample_d(mglGraph *gr, void *); //----------------------------------------------------------------------------- +//#define PTHREAD_SAMPLE +#ifdef PTHREAD_SAMPLE #include -#include +#endif mglPoint pnt; // some global variable for changable data void *mgl_wx_tmp(void *) { mglWxRun(); return 0; } //----------------------------------------------------------------------------- diff --git a/include/config.h.in b/include/config.h.in index 5356bcb..78639f8 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -3,14 +3,21 @@ /* This define enables double precision in MathGL */ #define MGL_USE_DOUBLE ${MGL_USE_DOUBLE} +#define MGL_NO_DATA_A ${MGL_NO_DATA_A} #define MGL_HAVE_GSL ${MGL_HAVE_GSL} #define MGL_HAVE_LTDL ${MGL_HAVE_LTDL} +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define MGL_HAVE_PTHREAD 0 +#else #define MGL_HAVE_PTHREAD ${MGL_HAVE_PTHREAD} +#endif #define MGL_HAVE_HDF4 ${MGL_HAVE_HDF4} #define MGL_HAVE_HDF5 ${MGL_HAVE_HDF5} #define MGL_HAVE_HDF5_18 ${MGL_HAVE_HDF5_18} #define MGL_HAVE_JPEG ${MGL_HAVE_JPEG} +#define MGL_HAVE_PNG ${MGL_HAVE_PNG} +#define MGL_HAVE_ZLIB ${MGL_HAVE_ZLIB} #define MGL_HAVE_U3D ${MGL_HAVE_U3D} #define MGL_HAVE_PDF ${MGL_HAVE_PDF} #define MGL_HAVE_GIF ${MGL_HAVE_GIF} @@ -22,5 +29,6 @@ #define MGL_HAVE_PYTHON ${MGL_HAVE_PYTHON} #define MGL_HAVE_OCTAVE ${MGL_HAVE_OCTAVE} #define MGL_HAVE_DOC ${MGL_HAVE_DOC} +#define MGL_HAVE_MPI ${MGL_HAVE_MPI} #endif diff --git a/include/mgl2/addon.h b/include/mgl2/addon.h index 9589f82..c5fa787 100644 --- a/include/mgl2/addon.h +++ b/include/mgl2/addon.h @@ -20,7 +20,6 @@ #ifndef _MGL_ADDON_H_ #define _MGL_ADDON_H_ /***************************************************************************/ -#include #ifdef __cplusplus /***************************************************************************/ #include @@ -53,7 +52,7 @@ int mgl_chrpos(const char *str,char fnd); /** Get uncommented string from file (NOTE: it is not thread safe!!!) */ char *mgl_fgetstr(FILE *fp); /** Check if symbol denote true */ -bool mgl_istrue(char ch); +int mgl_istrue(char ch); /** Print test message */ void mgl_test(const char *str, ...); /** Print info message */ diff --git a/include/mgl2/base.h b/include/mgl2/base.h index ba42576..ff57b3f 100644 --- a/include/mgl2/base.h +++ b/include/mgl2/base.h @@ -19,11 +19,7 @@ ***************************************************************************/ #ifndef _MGL_BASE_H_ #define _MGL_BASE_H_ -#include -#include -#include -#include -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(__BORLANDC__) #include #endif #include "mgl2/define.h" @@ -35,18 +31,33 @@ #include "mgl2/eval.h" #include "mgl2/font.h" //----------------------------------------------------------------------------- +class mglBase; +class mglData; +class mglParser; +class mglFormula; +typedef mglBase* HMGL; +typedef mglData* HMDT; +typedef mglParser* HMPR; +typedef mglFormula* HMEX; +//----------------------------------------------------------------------------- +#if MGL_NO_DATA_A +#define mglDataA mglData +typedef const mglData* HCDT; +#include "mgl2/data.h" +#else /// Abstract class for data array class mglDataA { public: + virtual ~mglDataA() {}; virtual mreal v(long i,long j=0,long k=0) const = 0; virtual mreal vthr(long i) const = 0; virtual long GetNx() const = 0; virtual long GetNy() const = 0; virtual long GetNz() const = 0; inline long GetNN() const { return GetNx()*GetNy()*GetNz(); } - virtual float Maximal() const = 0; - virtual float Minimal() const = 0; + virtual mreal Maximal() const = 0; + virtual mreal Minimal() const = 0; virtual mreal dvx(long i,long j=0,long k=0) const = 0; // { return i>0 ? (i0 ? (k Grp; ///< List of groups with names -- need for export std::string PlotId; ///< Id of plot for saving filename (in GLUT window for example) - float CDef; ///< Default (current) color in texture - float AlphaDef; ///< Default value of alpha channel (transparency) - float BarWidth; ///< Relative width of rectangles in Bars(). + mreal CDef; ///< Default (current) color in texture + mreal AlphaDef; ///< Default value of alpha channel (transparency) + mreal BarWidth; ///< Relative width of rectangles in Bars(). int MeshNum; ///< Set approximate number of lines in Mesh and Grid. By default (=0) it draw all lines. char Arrow1, Arrow2;///< Style of arrows at end and at start of curve long InUse; ///< Smart pointer (number of users) @@ -195,30 +203,32 @@ public: inline void set(bool v,long fl) { Flag = v ? Flag|fl : Flag&(~fl); } /// Set values of mglGraph::Min and mglGraph::Max - inline void SetRanges(float x1, float x2, float y1, float y2, float z1=0, float z2=0, float c1=0, float c2=0) + inline void SetRanges(mreal x1, mreal x2, mreal y1, mreal y2, mreal z1=0, mreal z2=0, mreal c1=0, mreal c2=0) { SetRanges(mglPoint(x1,y1,z1,c1),mglPoint(x2,y2,z2,c2)); } void SetRanges(mglPoint v1, mglPoint v2); /// Set values of mglGraph::Cmin and mglGraph::Cmax as minimal and maximal values of data a - void CRange(const mglDataA &a, bool add = false, float fact=0); - inline void CRange(float v1,float v2) { if(v1!=v2) {Min.c=v1; Max.c=v2; RecalcCRange();} } + void CRange(HCDT a, bool add = false, mreal fact=0); + inline void CRange(mreal v1,mreal v2) { if(v1!=v2) {Min.c=v1; Max.c=v2; RecalcCRange();} } /// Set values of mglGraph::Min.x and mglGraph::Max.x as minimal and maximal values of data a - void XRange(const mglDataA &a, bool add = false, float fact=0); - inline void XRange(float v1,float v2) { if(v1!=v2) {Min.x=v1; Max.x=v2; RecalcBorder();} } + void XRange(HCDT a, bool add = false, mreal fact=0); + inline void XRange(mreal v1,mreal v2) { if(v1!=v2) {Min.x=v1; Max.x=v2; RecalcBorder();} } /// Set values of mglGraph::Min.x and mglGraph::Max.x as minimal and maximal values of data a - void YRange(const mglDataA &a, bool add = false, float fact=0); - inline void YRange(float v1,float v2) { if(v1!=v2) {Min.y=v1; Max.y=v2; RecalcBorder();} } + void YRange(HCDT a, bool add = false, mreal fact=0); + inline void YRange(mreal v1,mreal v2) { if(v1!=v2) {Min.y=v1; Max.y=v2; RecalcBorder();} } /// Set values of mglGraph::Min.x and mglGraph::Max.x as minimal and maximal values of data a - void ZRange(const mglDataA &a, bool add = false, float fact=0); - inline void ZRange(float v1,float v2) { if(v1!=v2) {Min.z=v1; Max.z=v2; RecalcBorder();} } + void ZRange(HCDT a, bool add = false, mreal fact=0); + inline void ZRange(mreal v1,mreal v2) { if(v1!=v2) {Min.z=v1; Max.z=v2; RecalcBorder();} } /// Set ranges for automatic variables - void SetAutoRanges(float x1, float x2, float y1=0, float y2=0, float z1=0, float z2=0, float c1=0, float c2=0); + void SetAutoRanges(mreal x1, mreal x2, mreal y1=0, mreal y2=0, mreal z1=0, mreal z2=0, mreal c1=0, mreal c2=0); /// Set axis origin - inline void SetOrigin(float x0, float y0, float z0=NAN, float c0=NAN) + inline void SetOrigin(mreal x0, mreal y0, mreal z0=NAN, mreal c0=NAN) { Org=mglPoint(x0,y0,z0,c0); } /// Save ranges into internal variable and put parsed - float SaveState(const char *opt); + mreal SaveState(const char *opt); /// Load ranges from internal variable void LoadState(); + /// Increase ZMin + mreal AdjustZMin() { ZMin /= MGL_EPSILON; return Max.z - ZMin*(Max.z-Min.z); } /// Safetly set the transformation formulas for coordinate. void SetFunc(const char *EqX, const char *EqY, const char *EqZ=0, const char *EqA=0); @@ -232,7 +242,7 @@ public: /// Set cutting for points outside of bounding box inline void SetCut(bool val) { set(val, MGL_ENABLE_CUT); } /// Set additional cutting box - inline void SetCutBox(float x1, float y1, float z1, float x2, float y2, float z2) + inline void SetCutBox(mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2) { CutMin=mglPoint(x1,y1,z1); CutMax=mglPoint(x2,y2,z2); } inline void SetCutBox(mglPoint v1, mglPoint v2) { CutMin=v1; CutMax=v2; } @@ -240,14 +250,14 @@ public: virtual bool Light(bool enable) { bool t=get(MGL_ENABLE_LIGHT); set(enable,MGL_ENABLE_LIGHT); return t; } /// Set ambient light brightness - virtual void SetAmbient(float bright=0.5); + virtual void SetAmbient(mreal bright=0.5); /// Use diffusive light (only for local light sources) inline void SetDifLight(bool dif) { set(dif,MGL_DIFFUSIVE); } /// Set the transparency on/off. virtual bool Alpha(bool enable) { bool t=get(MGL_ENABLE_ALPHA); set(enable,MGL_ENABLE_ALPHA); return t; } /// Set default value of alpha-channel - inline void SetAlphaDef(float val) { AlphaDef=val; }; + inline void SetAlphaDef(mreal val) { AlphaDef=val; }; /// Set default palette inline void SetPalette(const char *colors) { Txt[0].Set(mgl_have_color(colors)?colors:MGL_DEF_PAL,-1); } @@ -259,14 +269,14 @@ 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(float val) { BarWidth=val; }; + inline void SetBarWidth(mreal val) { BarWidth=val; }; /// Set size of marks - inline void SetMarkSize(float val) { MarkSize=0.02*val; } + inline void SetMarkSize(mreal val) { MarkSize=0.02*val; } /// Set size of arrows - inline void SetArrowSize(float val) { ArrowSize=0.03*val; } + inline void SetArrowSize(mreal val) { ArrowSize=0.03*val; } /// Set warning code ant fill Message - void SetWarn(int code, const char *who=""); + void SetWarn(int code, const char *who); int inline GetWarn() const { return WarnCode; } virtual void StartAutoGroup (const char *)=0; @@ -276,11 +286,11 @@ public: inline void Highlight(int id) { HighId=id; } /// Set FontSize by size in pt and picture DPI (default is 16 pt for dpi=72) - virtual void SetFontSizePT(float pt, int dpi=72){ FontSize = pt*27.f/dpi; } + virtual void SetFontSizePT(mreal pt, int dpi=72){ FontSize = pt*27.f/dpi; } /// Set FontSize by size in centimeters and picture DPI (default is 0.56 cm = 16 pt) - inline void SetFontSizeCM(float cm, int dpi=72) { SetFontSizePT(cm*28.45f,dpi); }; + inline void SetFontSizeCM(mreal 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) - inline void SetFontSizeIN(float in, int dpi=72) { SetFontSizePT(in*72.27f,dpi); }; + inline void SetFontSizeIN(mreal in, int dpi=72) { SetFontSizePT(in*72.27f,dpi); }; /// Set font typeface. Note that each mglFont instance can be used with ONLY ONE mglGraph instance at a moment of time! void SetFont(mglFont *f); /// Get current typeface. Note that this variable can be deleted at next SetFont() call! @@ -293,14 +303,14 @@ public: /// Copy font from another mglGraph instance inline void CopyFont(mglBase *gr) { fnt->Copy(gr->GetFont()); } /// Set default font size - inline void SetFontSize(float val) { FontSize=val>0 ? val:FontSize*val; } - inline float GetFontSize() const { return FontSize; }; - inline float TextWidth(const wchar_t *text, const char *font, float size) const + inline void SetFontSize(mreal val) { FontSize=val>0 ? val:FontSize*val; } + inline mreal GetFontSize() const { return FontSize; }; + inline mreal TextWidth(const wchar_t *text, const char *font, mreal size) const { return (size<0?-size*FontSize:size)*font_factor*fnt->Width(text,(font&&*font)?font:FontDef)/8; } - inline float TextHeight(const char *font, float size) const + inline mreal TextHeight(const char *font, mreal size) const { return (size<0?-size*FontSize:size)*font_factor*fnt->Height(font?font:FontDef)/8; } - inline float FontFactor() const { return font_factor; } - virtual float GetRatio() const; + inline mreal FontFactor() const { return font_factor; } + virtual mreal GetRatio() const; /// Set to use or not text rotation inline void SetRotatedText(bool val) { set(val,MGL_ENABLE_RTEXT); } /// Set default font style and color @@ -322,8 +332,8 @@ public: // ~~~~~~~~~~~~~~~~~~~~~~ Developer functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// Add point to the pntN and return its position - long AddPnt(mglPoint p, float c=-1, mglPoint n=mglPoint(NAN), float a=-1, int scl=1); - long CopyNtoC(long k, float c); + long AddPnt(mglPoint p, mreal c=-1, mglPoint n=mglPoint(NAN), mreal a=-1, int scl=1); + long CopyNtoC(long k, mreal c); long CopyProj(long from, mglPoint p, mglPoint n); virtual void Reserve(long n); ///< Allocate n-cells for pntC and return current position /// Set to reduce accuracy of points (to reduc size of output files) @@ -344,34 +354,34 @@ public: /// Scale coordinates and cut off some points virtual bool ScalePoint(mglPoint &p, mglPoint &n, bool use_nan=true) const; - virtual float GetOrgX(char dir) const=0; ///< Get Org.x (parse NAN value) - virtual float GetOrgY(char dir) const=0; ///< Get Org.y (parse NAN value) - virtual float GetOrgZ(char dir) const=0; ///< Get Org.z (parse NAN value) + virtual mreal GetOrgX(char dir) const=0; ///< Get Org.x (parse NAN value) + virtual mreal GetOrgY(char dir) const=0; ///< Get Org.y (parse NAN value) + virtual mreal GetOrgZ(char dir) const=0; ///< Get Org.z (parse NAN value) /// Get color depending on single variable z, which should be scaled if scale=true - inline float GetC(long s,float z,bool scale = true) const - { return s+(scale?GetA(z):(z>0?z/MGL_FLT_EPS:0)); } + inline mreal GetC(long s,mreal z,bool scale = true) const + { return s+(scale?GetA(z):(z>0?z/MGL_EPSILON:0)); } /// Get alpha value depending on single variable \a a - float GetA(float a) const; + mreal GetA(mreal a) const; /// Set pen/palette char SetPenPal(const char *stl, long *id=0); /// Add texture (like color scheme) and return the position of first color long AddTexture(const char *cols, int smooth=0); -// inline float AddTexture(char col) { return AddTexture(mglColor(col)); }; - float AddTexture(mglColor col); +// inline mreal AddTexture(char col) { return AddTexture(mglColor(col)); }; + mreal AddTexture(mglColor col); inline void DefColor(mglColor col) { CDef = AddTexture(col); } /// Set next color from palette - float NextColor(long &id); + mreal NextColor(long &id); - virtual void mark_plot(long p, char type, float size=1)=0; + virtual void mark_plot(long p, char type, mreal size=1)=0; virtual void arrow_plot(long p1, long p2, char st)=0; 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 Glyph(float x, float y, float f, int style, long icode, float col)=0; - virtual float text_plot(long p,const wchar_t *text,const char *fnt,float size=-1,float sh=0,float col=-('k'),bool rot=true)=0; - void vect_plot(long p1, long p2, float s=1); - inline float mark_size() { return MarkSize*font_factor; } + virtual void Glyph(mreal x, mreal y, mreal f, int style, long icode, mreal col)=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); + inline mreal mark_size() { return MarkSize*font_factor; } // inline char last_color() { return last_style[1]; } inline const char *last_line() { return last_style; } @@ -392,13 +402,13 @@ protected: int TernAxis; ///< Flag that Ternary axis is used unsigned PDef; ///< Pen bit mask - float pPos; ///< Current position in pen mask - float PenWidth; ///< Pen width for further line plotting (must be >0 !!!) + mreal pPos; ///< Current position in pen mask + mreal PenWidth; ///< Pen width for further line plotting (must be >0 !!!) // long numT; ///< Number of textures - float AmbBr; ///< Default ambient light brightness + mreal AmbBr; ///< Default ambient light brightness mglFont *fnt; ///< Class for printing vector text - float FontSize; ///< The size of font for tick and axis labels + mreal FontSize; ///< The size of font for tick and axis labels 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) @@ -409,17 +419,17 @@ protected: mglFormula *fc; ///< Cutting off condition (formula). long CurrPal; ///< Current palette index - float MarkSize; ///< The size of marks for 1D plots. - float ArrowSize; ///< The size of arrows. + mreal MarkSize; ///< The size of marks for 1D plots. + mreal ArrowSize; ///< The size of arrows. char last_style[64];///< Last pen style - float font_factor; ///< Font scaling factor + mreal font_factor; ///< Font scaling factor virtual void LightScale()=0; ///< Scale positions of light sources private: mglPoint MinS; ///< Saved lower edge of bounding box for graphics. mglPoint MaxS; ///< Saved upper edge of bounding box for graphics. - float MSS, ASS, FSS, ADS, MNS, LSS; ///< Saved state + mreal MSS, ASS, FSS, ADS, MNS, LSS; ///< Saved state long CSS; ///< Saved flags bool saved; ///< State is saved std::string leg_str;///< text to be save in legend @@ -429,10 +439,17 @@ private: void RecalcCRange(); ///< Recalculate internal parameter for correct coloring. void RecalcBorder(); ///< Recalculate internal parameter for correct transformation rules. - void SetFBord(float x,float y,float z); ///< Set internal boundng box depending on transformation formula + void SetFBord(mreal x,mreal y,mreal z); ///< Set internal boundng box depending on transformation formula void ClearEq(); ///< Clear the used variables for axis transformation }; //----------------------------------------------------------------------------- +bool mgl_check_dim1(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT r, const char *name, bool less=false); +bool mgl_check_dim2(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *name, bool less=false); +bool mgl_check_dim3(HMGL gr, bool both, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *name); +bool mgl_check_vec3(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *name); +bool mgl_check_trig(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const char *name, int d=3); +bool mgl_isboth(HCDT x, HCDT y, HCDT z, HCDT a); +//----------------------------------------------------------------------------- #define _Da_(d) (*((const mglDataA *)(d))) #define _DA_(a) ((const mglDataA *)*(a)) #define _GR_ ((mglBase *)(*gr)) @@ -441,14 +458,6 @@ private: #define _DM_(a) ((mglData *)*(a)) #define _DT_ ((mglData *)*d) //----------------------------------------------------------------------------- -class mglData; -class mglParser; -class mglFormula; -typedef mglBase* HMGL; -typedef mglData* HMDT; -typedef mglParser* HMPR; -typedef mglFormula* HMEX; -typedef const mglDataA* HCDT; #else typedef void *HMGL; typedef void *HMDT; diff --git a/include/mgl2/base_cf.h b/include/mgl2/base_cf.h index e6dfd21..1391d2e 100644 --- a/include/mgl2/base_cf.h +++ b/include/mgl2/base_cf.h @@ -28,26 +28,29 @@ extern "C" { int mgl_get_warn(HMGL gr); void mgl_set_warn(HMGL gr, int code, const char *text); const char *mgl_get_mess(HMGL gr); +int mgl_get_flag(HMGL gr, long flag); +void mgl_set_flag(HMGL gr, int val, long flag); + long mgl_use_graph(HMGL gr, int inc); void mgl_start_group(HMGL gr, const char *); void mgl_end_group(HMGL gr); void mgl_highlight(HMGL gr, int id); void mgl_set_palette(HMGL gr, const char *colors); -void mgl_set_alpha_default(HMGL graph, float alpha); -void mgl_set_bar_width(HMGL graph, float width); +void mgl_set_alpha_default(HMGL graph, mreal alpha); +void mgl_set_bar_width(HMGL graph, mreal width); void mgl_set_meshnum(HMGL graph, int num); -void mgl_set_ambbr(HMGL gr, float i); +void mgl_set_ambbr(HMGL gr, mreal i); void mgl_set_light_dif(HMGL gr, int enable); void mgl_set_rdc_acc(HMGL graph, int reduce); void mgl_set_cut(HMGL graph, int cut); -void mgl_set_cut_box(HMGL gr, float x1,float y1,float z1,float x2,float y2,float z2); -void mgl_set_ranges(HMGL graph, float x1, float x2, float y1, float y2, float z1, float z2); -void mgl_set_range_val(HMGL gr, char dir, float v1,float v2); +void mgl_set_cut_box(HMGL gr, mreal x1,mreal y1,mreal z1,mreal x2,mreal y2,mreal z2); +void mgl_set_ranges(HMGL graph, mreal x1, mreal x2, mreal y1, mreal y2, mreal z1, mreal z2); +void mgl_set_range_val(HMGL gr, char dir, mreal v1,mreal v2); void mgl_set_range_dat(HMGL gr, char dir, HCDT a, int add); -void mgl_set_origin(HMGL graph, float x0, float y0, float z0); +void mgl_set_origin(HMGL graph, mreal x0, mreal y0, mreal z0); void mgl_set_func(HMGL graph, const char *EqX,const char *EqY,const char *EqZ,const char *EqA); void mgl_set_coor(HMGL gr, int how); void mgl_set_ternary(HMGL gr, int enable); @@ -56,24 +59,24 @@ void mgl_set_cutoff(HMGL graph, const char *EqC); void mgl_set_tick_rotate(HMGL graph, int enable); void mgl_set_tick_skip(HMGL graph, int enable); -float mgl_data_get_value(HCDT d, long i, long j, long k); +mreal mgl_data_get_value(HCDT d, long i, long j, long k); long mgl_data_get_nx(HCDT d); long mgl_data_get_ny(HCDT d); long mgl_data_get_nz(HCDT d); -void mgl_set_mark_size(HMGL graph, float size); -void mgl_set_arrow_size(HMGL graph, float size); -void mgl_set_font_size(HMGL graph, float size); +void mgl_set_mark_size(HMGL graph, mreal size); +void mgl_set_arrow_size(HMGL graph, mreal size); +void mgl_set_font_size(HMGL graph, mreal size); void mgl_set_font_def(HMGL graph, const char *fnt); void mgl_set_rotated_text(HMGL graph, int enable); void mgl_load_font(HMGL gr, const char *name, const char *path); void mgl_copy_font(HMGL gr, HMGL gr_from); void mgl_restore_font(HMGL gr); -void mgl_set_color(char id, float r, float g, float b); +void mgl_set_color(char id, mreal r, mreal g, mreal b); void mgl_set_def_sch(HMGL gr, const char *sch); /*****************************************************************************/ void mgl_set_def_sch_(uintptr_t *gr, const char *sch,int); -void mgl_set_color_(char *id, float *r, float *g, float *b, int); +void mgl_set_color_(char *id, mreal *r, mreal *g, mreal *b, int); int mgl_get_warn_(uintptr_t *gr); void mgl_set_warn_(uintptr_t *gr, int *code, const char *text,int); long mgl_use_graph_(uintptr_t *gr, int *inc); @@ -82,22 +85,22 @@ void mgl_end_group_(uintptr_t *gr); void mgl_highlight_(uintptr_t *gr, int *id); void mgl_set_palette_(uintptr_t *gr, const char *colors, int); -void mgl_set_pal_color_(uintptr_t *graph, int *n, float *r, float *g, float *b); +void mgl_set_pal_color_(uintptr_t *graph, int *n, mreal *r, mreal *g, mreal *b); void mgl_set_pal_num_(uintptr_t *graph, int *num); -void mgl_set_alpha_default_(uintptr_t *graph, float *alpha); -void mgl_set_bar_width_(uintptr_t *graph, float *width); +void mgl_set_alpha_default_(uintptr_t *graph, mreal *alpha); +void mgl_set_bar_width_(uintptr_t *graph, mreal *width); void mgl_set_meshnum_(uintptr_t *graph, int *num); -void mgl_set_ambbr_(uintptr_t *gr, float *i); +void mgl_set_ambbr_(uintptr_t *gr, mreal *i); void mgl_set_light_dif_(uintptr_t *graph, int *enable); void mgl_set_rdc_acc_(uintptr_t *graph, int *reduce); void mgl_set_cut_(uintptr_t *graph, int *cut); -void mgl_set_cut_box_(uintptr_t *gr, float *x1,float *y1,float *z1,float *x2,float *y2,float *z2); -void mgl_set_ranges_(uintptr_t *graph, float *x1, float *x2, float *y1, float *y2, float *z1, float *z2); -void mgl_set_range_val_(uintptr_t *gr, const char *dir, float *v1,float *v2,int); +void mgl_set_cut_box_(uintptr_t *gr, mreal *x1,mreal *y1,mreal *z1,mreal *x2,mreal *y2,mreal *z2); +void mgl_set_ranges_(uintptr_t *graph, mreal *x1, mreal *x2, mreal *y1, mreal *y2, mreal *z1, mreal *z2); +void mgl_set_range_val_(uintptr_t *gr, const char *dir, mreal *v1,mreal *v2,int); void mgl_set_range_dat_(uintptr_t *gr, const char *dir, uintptr_t *a, int *add,int); -void mgl_set_origin_(uintptr_t *gr, float *x0, float *y0, float *z0); +void mgl_set_origin_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0); void mgl_set_func_(uintptr_t *graph, const char *EqX, const char *EqY, const char *EqZ, const char *EqA, int, int, int, int); void mgl_set_coor_(uintptr_t *gr, int *how); void mgl_set_ternary_(uintptr_t *graph, int *enable); @@ -106,14 +109,14 @@ void mgl_set_cutoff_(uintptr_t *graph, const char *EqC, int); void mgl_set_tick_rotate_(uintptr_t *graph, int *enable); void mgl_set_tick_skip_(uintptr_t *graph, int *enable); -float mgl_data_get_value_(uintptr_t *d, int *i, int *j, int *k); +mreal mgl_data_get_value_(uintptr_t *d, int *i, int *j, int *k); long mgl_data_get_nx_(uintptr_t *d); long mgl_data_get_ny_(uintptr_t *d); long mgl_data_get_nz_(uintptr_t *d); -void mgl_set_mark_size_(uintptr_t *graph, float *size); -void mgl_set_arrow_size_(uintptr_t *graph, float *size); -void mgl_set_font_size_(uintptr_t *graph, float *size); +void mgl_set_mark_size_(uintptr_t *graph, mreal *size); +void mgl_set_arrow_size_(uintptr_t *graph, mreal *size); +void mgl_set_font_size_(uintptr_t *graph, mreal *size); void mgl_set_font_def_(uintptr_t *graph, const char *fnt, int); void mgl_set_rotated_text_(uintptr_t *graph, int *enable); void mgl_load_font_(uintptr_t *gr, char *name, char *path, int l, int n); diff --git a/include/mgl2/canvas.h b/include/mgl2/canvas.h index ee7a7f6..8937e3b 100644 --- a/include/mgl2/canvas.h +++ b/include/mgl2/canvas.h @@ -34,42 +34,43 @@ struct GifFileType; /// Structure for transformation matrix struct mglMatrix { - float b[9]; - float x,y,z,pf; + mreal b[9]; + mreal x,y,z,pf; mglMatrix() { clear(); } - inline void clear() { x=y=z=0; memset(b,0,9*sizeof(float)); b[0]=b[4]=b[8]=1; } - inline mglMatrix &operator=(mglMatrix &a) - { x=a.x; y=a.y; z=a.z; pf=a.pf; memcpy(b,a.b,9*sizeof(float)); return *this; } + inline void clear() { x=y=z=0; memset(b,0,9*sizeof(mreal)); b[0]=b[4]=b[8]=1; } + inline mglMatrix &operator=(const mglMatrix &a) + { x=a.x; y=a.y; z=a.z; pf=a.pf; memcpy(b,a.b,9*sizeof(mreal)); return *this; } }; //----------------------------------------------------------------------------- /// Structure for drawing axis and ticks struct mglAxis { - mglAxis() { dv=ds=d=v0=v1=v2=o=0; ns=f=ch=*t=0; } + mglAxis() { dv=ds=d=v0=v1=v2=o=sh=0; ns=f=ch=*t=0; } mglAxis(const mglAxis &aa) - { dv=aa.dv; ds=aa.ds; d=aa.d; dir=aa.dir; + { dv=aa.dv; ds=aa.ds; d=aa.d; dir=aa.dir; sh=aa.sh; v0=aa.v0; v1=aa.v1; v2=aa.v2; o=aa.o; a = aa.a; b = aa.b; org=aa.org; txt=aa.txt; ns=aa.ns; f=aa.f; ch=aa.ch; wcscpy(t,aa.t); } - inline void AddLabel(const wchar_t *lbl, float v) + inline void AddLabel(const wchar_t *lbl, mreal v) { txt.push_back(mglText(lbl,"",v)); } - inline void AddLabel(const std::wstring &lbl, float v) + inline void AddLabel(const std::wstring &lbl, mreal v) { txt.push_back(mglText(lbl,v)); } - float dv,ds; ///< Actual step for ticks and subticks. - float d; ///< Step for axis ticks (if positive) or its number (if negative). + mreal dv,ds; ///< Actual step for ticks and subticks. + mreal d; ///< Step for axis ticks (if positive) or its number (if negative). int ns; ///< Number of axis subticks. wchar_t t[256]; ///< Tick template (set NULL to use default one ("%.2g" in simplest case)) mglPoint dir; ///< Axis direction mglPoint a,b; ///< Directions of over axis mglPoint org; - float v0; ///< Center of axis cross section - float v1; ///< Minimal axis range. - float v2; ///< Maximal axis range. - float o; ///< Point of starting ticks numbering (if NAN then Org is used). + mreal v0; ///< Center of axis cross section + mreal v1; ///< Minimal axis range. + mreal v2; ///< Maximal axis range. + mreal o; ///< Point of starting ticks numbering (if NAN then Org is used). int f; ///< Flag 0x1 - time, 0x2 - manual, 0x4 - fixed dv std::vector txt; ///< Axis labels - char ch; ///< Character of axis (like 'x','y','z','c') + char ch; ///< Character of axis (like 'x','y','z','c') + mreal sh; ///< Extra shift of ticks and axis labels }; //----------------------------------------------------------------------------- /// Structure for light source @@ -81,8 +82,8 @@ struct mglLight 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) - float a; ///< Aperture of light sources - float b; ///< Brightness of light sources + mreal a; ///< Aperture of light sources + mreal b; ///< Brightness of light sources mglColor c; ///< Color of light sources }; //----------------------------------------------------------------------------- @@ -120,9 +121,9 @@ using mglBase::Light; void DefaultPlotParam(); /// Set angle of view indepently from mglCanvas::Rotate() - virtual void View(float tetx,float tetz,float tety=0); + virtual void View(mreal tetx,mreal tetz,mreal tety=0); /// Zoom in or zoom out (if Zoom(0, 0, 1, 1)) a part of picture - virtual void Zoom(float x1, float y1, float x2, float y2); + virtual void Zoom(mreal x1, mreal y1, mreal x2, mreal y2); /// Restore image after View() and Zoom() virtual void Restore() { Bp.clear(); Bp.pf=0; } @@ -131,36 +132,36 @@ using mglBase::Light; /// Push transformation matrix into stack inline void Push() { stack.push_back(B); } /// Set PlotFactor - inline void SetPlotFactor(float val) + inline void SetPlotFactor(mreal val) { if(val<=0) {B.pf=1.55; set(MGL_AUTO_FACTOR);} else {B.pf=val; clr(MGL_AUTO_FACTOR);} } /// Get PlotFactor - inline float GetPlotFactor() { return B.pf; } + inline mreal GetPlotFactor() { return B.pf; } /// Pop transformation matrix from stack inline void Pop() { B = stack.back(); stack.pop_back(); } /// Clear up the frame virtual void Clf(mglColor back=WC); /// Put further plotting in cell of stick rotated on angles tet, phi - void StickPlot(int num, int i, float tet, float phi); + void StickPlot(int num, int i, mreal tet, mreal phi); /// Put further plotting in some region of whole frame surface. - void InPlot(float x1,float x2,float y1,float y2,bool rel=true); - void InPlot(float x1,float x2,float y1,float y2, const char *style); + void InPlot(mreal x1,mreal x2,mreal y1,mreal y2,bool rel=true); + void InPlot(mreal x1,mreal x2,mreal y1,mreal y2, const char *style); /// Add title for current subplot/inplot - void Title(const char *title,const char *stl="#",float size=-2); - void Title(const wchar_t *title,const char *stl="#",float size=-2); + void Title(const char *title,const char *stl="#",mreal size=-2); + void Title(const wchar_t *title,const char *stl="#",mreal size=-2); /// Set aspect ratio for further plotting. - void Aspect(float Ax,float Ay,float Az); + void Aspect(mreal Ax,mreal Ay,mreal Az); /// Rotate a further plotting. - void Rotate(float TetX,float TetZ,float TetY=0); + void Rotate(mreal TetX,mreal TetZ,mreal TetY=0); /// Rotate a further plotting around vector {x,y,z}. - void RotateN(float Tet,float x,float y,float z); + void RotateN(mreal Tet,mreal x,mreal y,mreal z); /// Set perspective (in range [0,1)) for plot. Set to zero for switching off. - void Perspective(float a) { Bp.pf = fabs(a); } + void Perspective(mreal a) { Bp.pf = fabs(a); } /// Set size of frame in pixels. Normally this function is called internaly. virtual void SetSize(int w,int h); - /// Get ratio (float width)/(float height). - float GetRatio() const; + /// Get ratio (mreal width)/(mreal height). + mreal GetRatio() const; /// Get bitmap data prepared for saving to file virtual unsigned char **GetRGBLines(long &w, long &h, unsigned char *&f, bool alpha=false); /// Get RGB bitmap of current state image. @@ -177,8 +178,8 @@ using mglBase::Light; void MPI_Send(int id); /// Receive graphical information from node id using MPI void MPI_Recv(int id); - inline float GetDelay() const { return Delay; } - inline void SetDelay(float d) { Delay=d; } + inline mreal GetDelay() const { return Delay; } + inline void SetDelay(mreal d) { Delay=d; } /// Calculate 3D coordinate {x,y,z} for screen point {xs,ys} mglPoint CalcXYZ(int xs, int ys) const; @@ -216,12 +217,12 @@ using mglBase::Light; inline void SetTranspType(int val) { Flag=(Flag&(~3)) + (val&3); SetAxisStl(val==2?"w-":"k-"); } /// Set the fog distance or switch it off (if d=0). - virtual void Fog(float d, float dz=0.25); + virtual void Fog(mreal d, mreal dz=0.25); /// Switch on/off the specified light source. virtual void Light(int n, bool enable); /// Add a light source. - virtual void AddLight(int n,mglPoint r, mglPoint d, char c='w', float bright=0.5, float ap=0); - inline void AddLight(int n,mglPoint d, char c='w', float bright=0.5, float ap=0) + virtual void AddLight(int n,mglPoint r, mglPoint d, char c='w', mreal bright=0.5, mreal ap=0); + inline void AddLight(int n,mglPoint d, char c='w', mreal bright=0.5, mreal ap=0) { AddLight(n,mglPoint(NAN),d,c,bright,ap); } /// Set ticks position and text (\n separated). Use n=0 to disable this feature. @@ -235,18 +236,18 @@ using mglBase::Light; void SetTickTempl(char dir, const wchar_t *t); void SetTickTempl(char dir, const char *t); /// Set time templates for ticks - void SetTickTime(char dir, float d=0, const char *t=""); + void SetTickTime(char dir, mreal d=0, const char *t=""); /// Set the ticks parameters - void SetTicks(char dir, float d=0, int ns=0, float org=NAN); + void SetTicks(char dir, mreal d=0, int ns=0, mreal org=NAN); /// Auto adjust ticks void AdjustTicks(const char *dir="xyzc", bool force=false); /// Tune ticks - inline void SetTuneTicks(int tune, float pos=1.15) + inline void SetTuneTicks(int tune, mreal pos=1.15) { TuneTicks = tune; FactorPos = pos; }; /// Set ticks styles void SetAxisStl(const char *stl="k", const char *tck=0, const char *sub=0); /// Set ticks length - void SetTickLen(float tlen, float stt=1.); + void SetTickLen(mreal tlen, mreal stt=1.); /// Draws bounding box outside the plotting volume with color \a c. void Box(const char *col=0, bool ticks=true); @@ -255,34 +256,27 @@ using mglBase::Light; /// Draw grid lines perpendicular to direction determined by string parameter \a dir. void Grid(const char *dir="xyzt",const char *pen="B-"); /// Print the label \a text for axis \a dir. - void Label(char dir, const char *text, float pos=0, float shift=0); - void Labelw(char dir, const wchar_t *text, float pos=0, float shift=0); - - /// Print the \a text at arbitrary position of the picture \a x, \a y in range [0,1]x[0,1]. - void Label(float x, float y, const char *text, const char *fnt=0, bool rel=false); - void Labelw(float x, float y, const wchar_t *text, const char *fnt=0, bool rel=false); -// /// Print the title text for the picture -// void Title(const wchar_t *text,const char *font=0); -// void Title(const char *text,const char *font=0); + void Label(char dir, const char *text, mreal pos=0, mreal shift=0); + void Labelw(char dir, const wchar_t *text, mreal pos=0, mreal shift=0); /// Draw colorbar at edge of axis void Colorbar(const char *sch=0); - void Colorbar(const char *sch, float x, float y, float w, float h); + void Colorbar(const char *sch, mreal x, mreal y, mreal w, mreal h); /// Draw colorbar at edge of axis for manual colors void Colorbar(HCDT v, const char *sch=0); - void Colorbar(HCDT v, const char *sch, float x, float y, float w, float h); + void Colorbar(HCDT v, const char *sch, mreal x, mreal y, mreal w, mreal h); /// Draw legend of accumulated strings at position (x, y) by \a font with \a size - inline void Legend(float x, float y, const char *font="#", float size=-0.8, float llen=0.1) + inline void Legend(mreal x, mreal y, const char *font="#", mreal size=-0.8, mreal llen=0.1) { Legend(Leg,x,y,font,size,llen); } /// Draw legend of accumulated strings by \a font with \a size - inline void Legend(int where=0x3, const char *font="#", float size=-0.8, float llen=0.1) + inline void Legend(int where=0x3, const char *font="#", mreal size=-0.8, mreal llen=0.1) { Legend(Leg,(where&1)?1:0,(where&2)?1:0,font,size,llen); } /// Draw legend of accumulated strings by \a font with \a size - inline void Legend(const std::vector &leg, int where=3, const char *font="#", float size=-0.8, float llen=0) + inline void Legend(const std::vector &leg, int where=3, const char *font="#", mreal size=-0.8, mreal llen=0) { Legend(leg,(where&1)?1:0,(where&2)?1:0,font,size,llen); } /// Draw legend strings \a text at position (x, y) by \a font with \a size - void Legend(const std::vector &leg, float x, float y, const char *font="#", float size=-0.8, float llen=0); + void Legend(const std::vector &leg, mreal x, mreal y, const char *font="#", mreal size=-0.8, mreal llen=0); /// Number of marks in legend sample inline void SetLegendMarks(int num=1) { LegendMarks = num>0?num:1; }; @@ -290,9 +284,13 @@ using mglBase::Light; void EndGroup(); /// Retur color for primitive depending lighting mglColor GetColor(const mglPrim &p); + /// Set extra shift for tick and axis labels + inline void SetTickShift(mglPoint p) + { ax.sh = p.x; ay.sh = p.y; az.sh = p.z; ac.sh = p.c; } protected: - float Delay; ///< Delay for animation in seconds + mreal Delay; ///< Delay for animation in seconds + // NOTE: Z should be float for reducing space and for compatibility reasons float *Z; ///< Height for given level in Z-direction unsigned char *C; ///< Picture for given level in Z-direction int *OI; ///< ObjId arrays @@ -308,12 +306,12 @@ protected: mglAxis ax,ay,az,ac;///< Axis parameters int TuneTicks; ///< Draw tuned ticks with extracted common component - float FactorPos; ///< Position of axis ticks factor (0 at Min, 1 at Max, 1.1 is default) - float TickLen; ///< Length of tiks (subticks length is sqrt(1+st_t)=1.41... times smaller) + mreal FactorPos; ///< Position of axis ticks factor (0 at Min, 1 at Max, 1.1 is default) + mreal TickLen; ///< Length of tiks (subticks length is sqrt(1+st_t)=1.41... times smaller) char AxisStl[32]; ///< Axis line style. Default is "k" char TickStl[32]; ///< Tick line style. Default is "k" char SubTStl[32]; ///< Subtick line style. Default is "k" - float st_t; ///< Subtick-to-tick ratio (ls=lt/sqrt(1+st_t)). Default is 1. + mreal st_t; ///< Subtick-to-tick ratio (ls=lt/sqrt(1+st_t)). Default is 1. int CurFrameId; ///< Number of automaticle created frames int Width; ///< Width of the image @@ -322,10 +320,10 @@ protected: mglMatrix Bp; ///< Transformation matrix for View() and Zoom() mglMatrix B; ///< Transformation matrix mglMatrix B1; ///< Transformation matrix for colorbar - float inW, inH; ///< Width and height of last InPlot + mreal inW, inH; ///< Width and height of last InPlot mglLight light[10]; ///< Light sources - float FogDist; ///< Inverse fog distance (fog ~ exp(-FogDist*Z)) - float FogDz; ///< Relative shift of fog + mreal FogDist; ///< Inverse fog distance (fog ~ exp(-FogDist*Z)) + mreal FogDz; ///< Relative shift of fog /// Auto adjust ticks void AdjustTicks(mglAxis &aa, bool ff); @@ -352,27 +350,27 @@ protected: /// Get drawing data for i-th frame. void GetDrwDat(long i); - float GetOrgX(char dir) const; ///< Get Org.x (parse NAN value) - float GetOrgY(char dir) const; ///< Get Org.y (parse NAN value) - float GetOrgZ(char dir) const; ///< Get Org.z (parse NAN value) + mreal GetOrgX(char dir) const; ///< Get Org.x (parse NAN value) + mreal GetOrgY(char dir) const; ///< Get Org.y (parse NAN value) + mreal GetOrgZ(char dir) const; ///< Get Org.z (parse NAN value) - void mark_plot(long p, char type, float size=1); // position in pntC + void mark_plot(long p, char type, mreal size=1); // position in pntC void arrow_plot(long p1, long p2, char st); // position in pntC void line_plot(long p1, long p2); // position in pntC void trig_plot(long p1, long p2, long p3); // position in pntN void quad_plot(long p1, long p2, long p3, long p4); // position in pntN - void Glyph(float x, float y, float f, int style, long icode, float col); - float text_plot(long p,const wchar_t *text,const char *fnt,float size=-1,float sh=0,float col=-('k'), bool rot=true); // position in pntN + void Glyph(mreal x, mreal y, mreal f, int style, long icode, mreal col); + mreal text_plot(long p,const wchar_t *text,const char *fnt,mreal size=-1,mreal sh=0,mreal col=-('k'), bool rot=true); // position in pntN void add_prim(mglPrim &a); ///< add primitive to list - void mark_draw(long p, char type, float size, mglDrawReg *d); - void arrow_draw(long p1, long p2, char st, float size, mglDrawReg *d); + void mark_draw(long p, char type, mreal size, mglDrawReg *d); + void arrow_draw(long p1, long p2, char st, mreal size, mglDrawReg *d); virtual void line_draw(long p1, long p2, mglDrawReg *d); virtual void trig_draw(long p1, long p2, long p3, bool anorm, mglDrawReg *d); virtual void quad_draw(long p1, long p2, long p3, long p4, mglDrawReg *d); virtual void pnt_draw(long p, mglDrawReg *d); void glyph_draw(const mglPrim *P, mglDrawReg *d); - bool IsSame(const mglPrim &pr,float wp,mglColor cp,int st); + bool IsSame(const mglPrim &pr,mreal wp,mglColor cp,int st); // functions for multi-threading void PreparePrim(bool fast); @@ -388,22 +386,22 @@ protected: void PutDrawReg(mglDrawReg *d, const mglCanvas *gr); private: -// float _tetx,_tety,_tetz; // extra angles +// mreal _tetx,_tety,_tetz; // extra angles std::vector stack; ///< stack for transformation matrixes int dr_nx1, dr_nx2, dr_ny1, dr_ny2; // Allowed drawing region GifFileType *gif; - float fscl,ftet; ///< last scale and rotation for glyphs + mreal fscl,ftet; ///< last scale and rotation for glyphs /// Draw generic colorbar - void colorbar(HCDT v, const float *s, int where, float x, float y, float w, float h); + void colorbar(HCDT v, const mreal *s, int where, mreal x, mreal y, mreal w, mreal h); /// Draw labels for ticks void DrawLabels(mglAxis &aa); /// Draw tick void tick_draw(mglPoint o, mglPoint d1, mglPoint d2, int f, const char *stl); /// Plot point \a p with color \a c - void pnt_plot(long x,long y,float z,const unsigned char c[4]); - float FindOptOrg(char dir, int ind) const; - /// Transform float color and alpha to bits format + void pnt_plot(long x,long y,mreal z,const unsigned char c[4]); + mreal FindOptOrg(char dir, int ind) const; + /// Transform mreal color and alpha to bits format unsigned char* col2int(const mglPnt &p, unsigned char *r); /// Combine colors in 2 plane. void combine(unsigned char *c1,unsigned char *c2); @@ -417,9 +415,9 @@ private: inline void PostScale(mglPoint *p,long n) const { for(long i=0;i +#include //----------------------------------------------------------------------------- /// Class for working with data array +#if MGL_NO_DATA_A +class mglData +#else class mglData : public mglDataA +#endif { public: @@ -35,14 +40,17 @@ 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 - char *id; ///< column (or slice) names + std::string id; ///< column (or slice) names +// char *id; ///< column (or slice) names bool link; ///< use external data (i.e. don't free it) /// Initiate by other mglData variable inline mglData(const mglData &d) { a=0; mgl_data_set(this,&d); } inline mglData(const mglDataA *d) { a=0; mgl_data_set(this, d); } inline mglData(bool, mglData *d) // NOTE: Variable d will be deleted!!! - { if(d) {memcpy((void*)this,(void*)d,sizeof(mglData)); d->id=0; d->link=true; delete d; } + { if(d) + { nx=d->nx; ny=d->ny; nz=d->nz; a=d->a; d->a=0; + id=d->id; link=d->link; delete d; } else { a=0; Create(1); } } /// Initiate by flat array inline mglData(int size, const float *d) { a=0; Set(d,size); } @@ -56,7 +64,7 @@ public: /// Allocate the memory for data array and initialize it zero inline mglData(long xx=1,long yy=1,long zz=1) { a=0; Create(xx,yy,zz); } /// Delete the array - virtual ~mglData() { if(id && a) delete []id; if(!link && a) delete []a; } + virtual ~mglData() { if(!link && a) delete []a; } inline mreal GetVal(long i, long j=0, long k=0) { return mgl_data_get_value(this,i,j,k);} inline void SetVal(mreal f, long i, long j=0, long k=0) @@ -154,6 +162,9 @@ public: /// Eqidistantly fill the data to range [x1,x2] in direction \a dir inline void Fill(mreal x1,mreal x2=NaN,char dir='x') { return mgl_data_fill(this,x1,x2,dir); } + /// Set the data by triangulated surface values assuming x,y,z in range [r1,r2] + inline void Grid(mglBase *gr, const mglData &x, const mglData &y, const mglData &z, const char *opt="") + { mgl_data_grid(gr,this,&x,&y,&z,opt); } /// Put value to data element(s) inline void Put(mreal val, long i=-1, long j=-1, long k=-1) { mgl_data_put_val(this,val,i,j,k); } @@ -164,8 +175,7 @@ public: inline void SetColumnId(const char *ids) { mgl_data_set_id(this,ids); } /// Make new id - inline void NewId() - { delete []id; id=new char[nx]; memset(id,0,nx*sizeof(char)); } + inline void NewId() { id.clear(); } /// Read data from tab-separated text file with auto determining size inline bool Read(const char *fname) @@ -313,9 +323,9 @@ public: inline void PrintInfo(FILE *fp) const { if(fp) { fprintf(fp,"%s",mgl_data_info(this)); fflush(fp); } } /// Get maximal value of the data - inline float Maximal() const { return mgl_data_max(this); } + inline mreal Maximal() const { return mgl_data_max(this); } /// Get minimal value of the data - inline float Minimal() const { return mgl_data_min(this); } + inline mreal Minimal() const { return mgl_data_min(this); } /// Get maximal value of the data and its position inline mreal Maximal(long &i,long &j,long &k) const { return mgl_data_max_int(this,&i,&j,&k); } @@ -373,7 +383,11 @@ public: inline mreal &operator[](long i) { return a[i]; } // NOTE see 13.10 for operator(), operator[] -- m.b. I should add it ??? #endif +#if MGL_NO_DATA_A + inline long GetNN() const { return nx*ny*nz; } +#else protected: +#endif /// Get the value in given cell of the data without border checking inline mreal v(long i,long j=0,long k=0) const #ifdef DEBUG @@ -459,10 +473,10 @@ inline mglData mglJacobian(const mglData &x, const mglData &y) inline mglData mglJacobian(const mglData &x, const mglData &y, const mglData &z) { return mglData(true, mgl_jacobian_3d(&x, &y, &z)); } /// Do something like Delone triangulation -inline mglData mglTriangulation(const mglData &x, const mglData &y, const mglData &z, float er=0) -{ return mglData(true,mgl_triangulation_3d(&x,&y,&z,er)); } -inline mglData mglTriangulation(const mglData &x, const mglData &y, float er=0) -{ return mglData(true,mgl_triangulation_2d(&x,&y,er)); } +inline mglData mglTriangulation(const mglData &x, const mglData &y, const mglData &z) +{ 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)); } //----------------------------------------------------------------------------- #endif #endif diff --git a/include/mgl2/data_cf.h b/include/mgl2/data_cf.h index fe3c1d8..1c894cc 100644 --- a/include/mgl2/data_cf.h +++ b/include/mgl2/data_cf.h @@ -62,8 +62,8 @@ void mgl_data_set_double3(HMDT d, const double ***A,long N1,long N2,long N3); void mgl_data_set(HMDT dat, HCDT a); void mgl_data_set_vector(HMDT dat, gsl_vector *v); void mgl_data_set_matrix(HMDT dat, gsl_matrix *m); -void mgl_data_set_value(HMDT dat, float v, long i, long j, long k); -float mgl_data_get_value(HCDT dat, long i, long j, long k); +void mgl_data_set_value(HMDT dat, mreal v, long i, long j, long k); +mreal mgl_data_get_value(HCDT dat, long i, long j, long k); void mgl_data_set_values(HMDT dat, const char *val, long nx, long ny, long nz); int mgl_data_read_hdf(HMDT d,const char *fname,const char *data); @@ -75,38 +75,39 @@ int mgl_data_read_dim(HMDT dat, const char *fname,long mx,long my,long mz); int mgl_data_read_range(HMDT d, const char *templ, double from, double to, double step, int as_slice); int mgl_data_read_all(HMDT dat, const char *templ, int as_slice); void mgl_data_save(HCDT dat, const char *fname,long ns); -void mgl_data_export(HCDT dat, const char *fname, const char *scheme,float v1,float v2,long ns); -void mgl_data_import(HMDT dat, const char *fname, const char *scheme,float v1,float v2); +void mgl_data_export(HCDT dat, const char *fname, const char *scheme,mreal v1,mreal v2,long ns); +void mgl_data_import(HMDT dat, const char *fname, const char *scheme,mreal v1,mreal v2); void mgl_data_create(HMDT dat, long nx,long ny,long nz); void mgl_data_transpose(HMDT dat, const char *dim); -void mgl_data_norm(HMDT dat, float v1,float v2,long sym,long dim); -void mgl_data_norm_slice(HMDT dat, float v1,float v2,char dir,long keep_en,long sym); +void mgl_data_norm(HMDT dat, mreal v1,mreal v2,long sym,long dim); +void mgl_data_norm_slice(HMDT dat, mreal v1,mreal v2,char dir,long keep_en,long sym); HMDT mgl_data_subdata(HCDT dat, long xx,long yy,long zz); HMDT mgl_data_subdata_ext(HCDT dat, HCDT xx, HCDT yy, HCDT zz); HMDT mgl_data_column(HCDT dat, const char *eq); void mgl_data_set_id(HMDT d, const char *id); -void mgl_data_fill(HMDT dat, float x1,float x2,char dir); +void mgl_data_fill(HMDT dat, mreal x1,mreal x2,char dir); void mgl_data_fill_eq(HMGL gr, HMDT dat, const char *eq, HCDT vdat, HCDT wdat,const char *opt); +void mgl_data_grid(HMGL gr, HMDT d, HCDT xdat, HCDT ydat, HCDT zdat,const char *opt); void mgl_data_put_val(HMDT dat, mreal val, long i, long j, long k); void mgl_data_put_dat(HMDT dat, HCDT val, long i, long j, long k); void mgl_data_modify(HMDT dat, const char *eq,long dim); void mgl_data_modify_vw(HMDT dat, const char *eq,HCDT vdat,HCDT wdat); void mgl_data_squeeze(HMDT dat, long rx,long ry,long rz,long smooth); -float mgl_data_max(HCDT dat); -float mgl_data_min(HCDT dat); +mreal mgl_data_max(HCDT dat); +mreal mgl_data_min(HCDT dat); mreal *mgl_data_value(HMDT dat, long i,long j,long k); mreal *mgl_data_data(HMDT dat); -float mgl_data_first(HCDT dat, const char *cond, long *i, long *j, long *k); -float mgl_data_last(HCDT dat, const char *cond, long *i, long *j, long *k); +mreal mgl_data_first(HCDT dat, const char *cond, long *i, long *j, long *k); +mreal mgl_data_last(HCDT dat, const char *cond, long *i, long *j, long *k); long mgl_data_find(HCDT dat, const char *cond, char dir, long i, long j, long k); int mgl_data_find_any(HCDT dat, const char *cond); -float mgl_data_max_int(HCDT dat, long *i, long *j, long *k); -float mgl_data_max_real(HCDT dat, mreal *x, mreal *y, mreal *z); -float mgl_data_min_int(HCDT dat, long *i, long *j, long *k); -float mgl_data_min_real(HCDT dat, mreal *x, mreal *y, mreal *z); -float mgl_data_momentum_val(HCDT d, char dir, mreal *m, mreal *w, mreal *s, mreal *k); +mreal mgl_data_max_int(HCDT dat, long *i, long *j, long *k); +mreal mgl_data_max_real(HCDT dat, mreal *x, mreal *y, mreal *z); +mreal mgl_data_min_int(HCDT dat, long *i, long *j, long *k); +mreal mgl_data_min_real(HCDT dat, mreal *x, mreal *y, mreal *z); +mreal mgl_data_momentum_val(HCDT d, char dir, mreal *m, mreal *w, mreal *s, mreal *k); HMDT mgl_data_combine(HCDT dat1, HCDT dat2); void mgl_data_extend(HMDT dat, long n1, long n2); @@ -115,7 +116,7 @@ void mgl_data_delete(HMDT dat, char dir, long at, long num); /*****************************************************************************/ /* Data manipulation functions */ /*****************************************************************************/ -void mgl_data_smooth(HMDT d, const char *dirs, float delta); +void mgl_data_smooth(HMDT d, const char *dirs, mreal delta); HMDT mgl_data_sum(HCDT dat, const char *dir); HMDT mgl_data_max_dir(HCDT dat, const char *dir); HMDT mgl_data_min_dir(HCDT dat, const char *dir); @@ -134,17 +135,17 @@ void mgl_data_sinfft(HMDT dat, const char *dir); void mgl_data_cosfft(HMDT dat, const char *dir); void mgl_data_fill_sample(HMDT dat, const char *how); -float mgl_data_spline(HCDT dat, float x,float y,float z); -float mgl_data_linear(HCDT dat, float x,float y,float z); +mreal mgl_data_spline(HCDT dat, mreal x,mreal y,mreal z); +mreal mgl_data_linear(HCDT dat, mreal x,mreal y,mreal z); HMDT mgl_data_trace(HCDT d); HMDT mgl_data_resize(HCDT dat, long mx,long my,long mz); -HMDT mgl_data_resize_box(HCDT dat, long mx,long my,long mz,float x1,float x2,float y1,float y2,float z1,float z2); -HMDT mgl_data_hist(HCDT dat, long n, float v1, float v2, long nsub); -HMDT mgl_data_hist_w(HCDT dat, HCDT weight, long n, float v1, float v2, long nsub); +HMDT mgl_data_resize_box(HCDT dat, long mx,long my,long mz,mreal x1,mreal x2,mreal y1,mreal y2,mreal z1,mreal z2); +HMDT mgl_data_hist(HCDT dat, long n, mreal v1, mreal v2, long nsub); +HMDT mgl_data_hist_w(HCDT dat, HCDT weight, long n, mreal v1, mreal v2, long nsub); HMDT mgl_data_momentum(HCDT dat, char dir, const char *how); HMDT mgl_data_evaluate(HCDT dat, HCDT idat, HCDT jdat, HCDT kdat, int norm); void mgl_data_envelop(HMDT dat, char dir); -void mgl_data_sew(HMDT dat, const char *dirs, float da); +void mgl_data_sew(HMDT dat, const char *dirs, mreal da); void mgl_data_crop(HMDT dat, long n1, long n2, char dir); /*****************************************************************************/ /* Data operations */ @@ -153,14 +154,14 @@ void mgl_data_mul_dat(HMDT dat, HCDT d); void mgl_data_div_dat(HMDT dat, HCDT d); void mgl_data_add_dat(HMDT dat, HCDT d); void mgl_data_sub_dat(HMDT dat, HCDT d); -void mgl_data_mul_num(HMDT dat, float d); -void mgl_data_div_num(HMDT dat, float d); -void mgl_data_add_num(HMDT dat, float d); -void mgl_data_sub_num(HMDT dat, float d); +void mgl_data_mul_num(HMDT dat, mreal d); +void mgl_data_div_num(HMDT dat, mreal d); +void mgl_data_add_num(HMDT dat, mreal d); +void mgl_data_sub_num(HMDT dat, mreal d); /*****************************************************************************/ -HMDT mgl_pde_solve(HMGL gr, const char *ham, HCDT ini_re, HCDT ini_im, float dz, float k0,const char *opt); -HMDT mgl_qo2d_solve(const char *ham, HCDT ini_re, HCDT ini_im, HCDT ray, float r, float k0, HMDT xx, HMDT yy); -HMDT mgl_ray_trace(const char *ham, float x0, float y0, float z0, float px, float py, float pz, float dt, float tmax); +HMDT mgl_pde_solve(HMGL gr, const char *ham, HCDT ini_re, HCDT ini_im, mreal dz, mreal k0,const char *opt); +HMDT mgl_qo2d_solve(const char *ham, HCDT ini_re, HCDT ini_im, HCDT ray, mreal r, mreal k0, HMDT xx, HMDT yy); +HMDT mgl_ray_trace(const char *ham, mreal x0, mreal y0, mreal z0, mreal px, mreal py, mreal pz, mreal dt, mreal tmax); HMDT mgl_jacobian_2d(HCDT x, HCDT y); HMDT mgl_jacobian_3d(HCDT x, HCDT y, HCDT z); HMDT mgl_transform_a(HCDT am, HCDT ph, const char *tr); @@ -168,8 +169,8 @@ HMDT mgl_transform(HCDT re, HCDT im, const char *tr); void mgl_data_fourier(HMDT re, HMDT im, const char *dir); HMDT mgl_data_stfa(HCDT re, HCDT im, long dn, char dir); -HMDT mgl_triangulation_3d(HCDT x, HCDT y, HCDT z, float er); -HMDT mgl_triangulation_2d(HCDT x, HCDT y, float er); +HMDT mgl_triangulation_3d(HCDT x, HCDT y, HCDT z); +HMDT mgl_triangulation_2d(HCDT x, HCDT y); /*****************************************************************************/ /* Data creation functions */ /*****************************************************************************/ @@ -184,42 +185,43 @@ void mgl_data_set_float3_(uintptr_t *d, const float *A,int *N1,int *N2,int *N3); void mgl_data_set_double3_(uintptr_t *d, const double *A,int *N1,int *N2,int *N3); void mgl_data_set_(uintptr_t *dat, uintptr_t *a); -void mgl_data_set_value_(uintptr_t *d, float *v, int *i, int *j, int *k); +void mgl_data_set_value_(uintptr_t *d, mreal *v, int *i, int *j, int *k); void mgl_data_set_values_(uintptr_t *d, const char *val, int *nx, int *ny, int *nz, int l); -float mgl_data_get_value_(uintptr_t *d, int *i, int *j, int *k); +mreal mgl_data_get_value_(uintptr_t *d, int *i, int *j, int *k); int mgl_data_read_(uintptr_t *d, const char *fname,int l); int mgl_data_read_mat_(uintptr_t *dat, const char *fname, int *dim, int); int mgl_data_read_dim_(uintptr_t *dat, const char *fname,int *mx,int *my,int *mz,int); void mgl_data_save_(uintptr_t *dat, const char *fname,int *ns,int); -void mgl_data_export_(uintptr_t *dat, const char *fname, const char *scheme,float *v1,float *v2,int *ns,int,int); -void mgl_data_import_(uintptr_t *dat, const char *fname, const char *scheme,float *v1,float *v2,int,int); +void mgl_data_export_(uintptr_t *dat, const char *fname, const char *scheme,mreal *v1,mreal *v2,int *ns,int,int); +void mgl_data_import_(uintptr_t *dat, const char *fname, const char *scheme,mreal *v1,mreal *v2,int,int); void mgl_data_create_(uintptr_t *dat, int *nx,int *ny,int *nz); void mgl_data_transpose_(uintptr_t *dat, const char *dim,int); -void mgl_data_norm_(uintptr_t *dat, float *v1,float *v2,int *sym,int *dim); -void mgl_data_norm_slice_(uintptr_t *dat, float *v1,float *v2,char *dir,int *keep_en,int *sym,int l); +void mgl_data_norm_(uintptr_t *dat, mreal *v1,mreal *v2,int *sym,int *dim); +void mgl_data_norm_slice_(uintptr_t *dat, mreal *v1,mreal *v2,char *dir,int *keep_en,int *sym,int l); uintptr_t mgl_data_subdata_(uintptr_t *dat, int *xx,int *yy,int *zz); uintptr_t mgl_data_subdata_ext_(uintptr_t *dat, uintptr_t *xx,uintptr_t *yy,uintptr_t *zz); uintptr_t mgl_data_column_(uintptr_t *dat, const char *eq,int l); void mgl_data_set_id_(uintptr_t *dat, const char *id,int l); -void mgl_data_fill_(uintptr_t *dat, float *x1,float *x2,const char *dir,int); +void mgl_data_fill_(uintptr_t *dat, mreal *x1,mreal *x2,const char *dir,int); void mgl_data_fill_eq_(uintptr_t *gr, uintptr_t *dat, const char *eq, uintptr_t *vdat, uintptr_t *wdat,const char *opt, int, int); -void mgl_data_put_val_(uintptr_t *dat, float *val, int *i, int *j, int *k); +void mgl_data_grid_(uintptr_t *gr, uintptr_t *dat, uintptr_t *xdat, uintptr_t *ydat, uintptr_t *zdat, const char *opt,int); +void mgl_data_put_val_(uintptr_t *dat, mreal *val, int *i, int *j, int *k); void mgl_data_put_dat_(uintptr_t *dat, uintptr_t *val, int *i, int *j, int *k); void mgl_data_modify_(uintptr_t *dat, const char *eq,int *dim,int); void mgl_data_modify_vw_(uintptr_t *dat, const char *eq, uintptr_t *vdat, uintptr_t *wdat,int); void mgl_data_squeeze_(uintptr_t *dat, int *rx,int *ry,int *rz,int *smooth); -float mgl_data_max_(uintptr_t *dat); -float mgl_data_min_(uintptr_t *dat); +mreal mgl_data_max_(uintptr_t *dat); +mreal mgl_data_min_(uintptr_t *dat); -float mgl_data_first_(uintptr_t *dat, const char *cond, int *i, int *j, int *k, int); -float mgl_data_last_(uintptr_t *dat, const char *cond, int *i, int *j, int *k, int); +mreal mgl_data_first_(uintptr_t *dat, const char *cond, int *i, int *j, int *k, int); +mreal mgl_data_last_(uintptr_t *dat, const char *cond, int *i, int *j, int *k, int); int mgl_data_find_(uintptr_t *dat, const char *cond, char *dir, int *i, int *j, int *k, int,int); int mgl_data_find_any_(uintptr_t *dat, const char *cond, int); -float mgl_data_max_int_(uintptr_t *dat, int *i, int *j, int *k); -float mgl_data_max_real_(uintptr_t *dat, float *x, float *y, float *z); -float mgl_data_min_int_(uintptr_t *dat, int *i, int *j, int *k); -float mgl_data_min_real_(uintptr_t *dat, float *x, float *y, float *z); -float mgl_data_momentum_val_(uintptr_t *dat, char *dir, float *m, float *w, float *s, float *k,int); +mreal mgl_data_max_int_(uintptr_t *dat, int *i, int *j, int *k); +mreal mgl_data_max_real_(uintptr_t *dat, mreal *x, mreal *y, mreal *z); +mreal mgl_data_min_int_(uintptr_t *dat, int *i, int *j, int *k); +mreal mgl_data_min_real_(uintptr_t *dat, mreal *x, mreal *y, mreal *z); +mreal mgl_data_momentum_val_(uintptr_t *dat, char *dir, mreal *m, mreal *w, mreal *s, mreal *k,int); uintptr_t mgl_data_combine_(uintptr_t *dat1, uintptr_t *dat2); void mgl_data_extend_(uintptr_t *dat, int *n1, int *n2); @@ -228,7 +230,7 @@ void mgl_data_delete_(uintptr_t *dat, const char *dir, int *at, int *num, int); /*****************************************************************************/ /* Data manipulation functions */ /*****************************************************************************/ -void mgl_data_smooth_(uintptr_t *dat, const char *dirs, float *delta,int); +void mgl_data_smooth_(uintptr_t *dat, const char *dirs, mreal *delta,int); uintptr_t mgl_data_sum_(uintptr_t *dat, const char *dir,int); uintptr_t mgl_data_max_dir_(uintptr_t *dat, const char *dir,int); uintptr_t mgl_data_min_dir_(uintptr_t *dat, const char *dir,int); @@ -247,17 +249,17 @@ void mgl_data_sinfft_(uintptr_t *dat, const char *dir,int); void mgl_data_cosfft_(uintptr_t *dat, const char *dir,int); void mgl_data_fill_sample_(uintptr_t *dat, const char *how,int); -float mgl_data_spline_(uintptr_t *dat, float *x,float *y,float *z); -float mgl_data_linear_(uintptr_t *dat, float *x,float *y,float *z); +mreal mgl_data_spline_(uintptr_t *dat, mreal *x,mreal *y,mreal *z); +mreal mgl_data_linear_(uintptr_t *dat, mreal *x,mreal *y,mreal *z); uintptr_t mgl_data_trace_(uintptr_t *d); uintptr_t mgl_data_resize_(uintptr_t *dat, int *mx,int *my,int *mz); -uintptr_t mgl_data_resize_box_(uintptr_t *dat, int *mx,int *my,int *mz,float *x1,float *x2,float *y1,float *y2,float *z1,float *z2); +uintptr_t mgl_data_resize_box_(uintptr_t *dat, int *mx,int *my,int *mz,mreal *x1,mreal *x2,mreal *y1,mreal *y2,mreal *z1,mreal *z2); uintptr_t mgl_data_momentum_(uintptr_t *dat, char *dir, const char *how, int,int); -uintptr_t mgl_data_hist_(uintptr_t *dat, int *n, float *v1, float *v2, int *nsub); -uintptr_t mgl_data_hist_w_(uintptr_t *dat, uintptr_t *weight, int *n, float *v1, float *v2, int *nsub); +uintptr_t mgl_data_hist_(uintptr_t *dat, int *n, mreal *v1, mreal *v2, int *nsub); +uintptr_t mgl_data_hist_w_(uintptr_t *dat, uintptr_t *weight, int *n, mreal *v1, mreal *v2, int *nsub); uintptr_t mgl_data_evaluate_(uintptr_t *dat, uintptr_t *idat, uintptr_t *jdat, uintptr_t *kdat, int *norm); void mgl_data_envelop_(uintptr_t *dat, const char *dir, int); -void mgl_data_sew_(uintptr_t *dat, const char *dirs, float *da, int); +void mgl_data_sew_(uintptr_t *dat, const char *dirs, mreal *da, int); void mgl_data_crop_(uintptr_t *dat, int *n1, int *n2, const char *dir,int); /*****************************************************************************/ /* Data operations */ @@ -266,16 +268,16 @@ void mgl_data_mul_dat_(uintptr_t *dat, uintptr_t *d); void mgl_data_div_dat_(uintptr_t *dat, uintptr_t *d); void mgl_data_add_dat_(uintptr_t *dat, uintptr_t *d); void mgl_data_sub_dat_(uintptr_t *dat, uintptr_t *d); -void mgl_data_mul_num_(uintptr_t *dat, float *d); -void mgl_data_div_num_(uintptr_t *dat, float *d); -void mgl_data_add_num_(uintptr_t *dat, float *d); -void mgl_data_sub_num_(uintptr_t *dat, float *d); +void mgl_data_mul_num_(uintptr_t *dat, mreal *d); +void mgl_data_div_num_(uintptr_t *dat, mreal *d); +void mgl_data_add_num_(uintptr_t *dat, mreal *d); +void mgl_data_sub_num_(uintptr_t *dat, mreal *d); /*****************************************************************************/ /* Nonlinear fitting */ /*****************************************************************************/ -uintptr_t mgl_pde_solve_(uintptr_t* gr, const char *ham, uintptr_t* ini_re, uintptr_t* ini_im, float *dz, float *k0,const char *opt,int,int); -uintptr_t mgl_qo2d_solve_(const char *ham, uintptr_t* ini_re, uintptr_t* ini_im, uintptr_t* ray, float *r, float *k0, uintptr_t* xx, uintptr_t* yy, int); -uintptr_t mgl_ray_trace_(const char *ham, float *x0, float *y0, float *z0, float *px, float *py, float *pz, float *dt, float *tmax,int); +uintptr_t mgl_pde_solve_(uintptr_t* gr, const char *ham, uintptr_t* ini_re, uintptr_t* ini_im, mreal *dz, mreal *k0,const char *opt,int,int); +uintptr_t mgl_qo2d_solve_(const char *ham, uintptr_t* ini_re, uintptr_t* ini_im, uintptr_t* ray, mreal *r, mreal *k0, uintptr_t* xx, uintptr_t* yy, int); +uintptr_t mgl_ray_trace_(const char *ham, mreal *x0, mreal *y0, mreal *z0, mreal *px, mreal *py, mreal *pz, mreal *dt, mreal *tmax,int); uintptr_t mgl_jacobian_2d_(uintptr_t* x, uintptr_t* y); uintptr_t mgl_jacobian_3d_(uintptr_t* x, uintptr_t* y, uintptr_t* z); @@ -284,8 +286,8 @@ uintptr_t mgl_transform_(uintptr_t *re, uintptr_t *im, const char *tr, int); void mgl_data_fourier_(uintptr_t *re, uintptr_t *im, const char *dir, int l); uintptr_t mgl_data_stfa_(uintptr_t *re, uintptr_t *im, int *dn, char *dir, int); -uintptr_t mgl_triangulation_3d_(uintptr_t *x, uintptr_t *y, uintptr_t *z, float *er); -uintptr_t mgl_triangulation_2d_(uintptr_t *x, uintptr_t *y, float *er); +uintptr_t mgl_triangulation_3d_(uintptr_t *x, uintptr_t *y, uintptr_t *z); +uintptr_t mgl_triangulation_2d_(uintptr_t *x, uintptr_t *y); /*****************************************************************************/ int mgl_data_read_hdf_(uintptr_t *d, const char *fname, const char *data,int l,int n); void mgl_data_link_(uintptr_t *d, float *A, int *nx,int *ny,int *nz); diff --git a/include/mgl2/define.h b/include/mgl2/define.h index a0a3471..b95a7ac 100644 --- a/include/mgl2/define.h +++ b/include/mgl2/define.h @@ -20,18 +20,42 @@ #ifndef _MGL_DEFINE_H_ #define _MGL_DEFINE_H_ //----------------------------------------------------------------------------- +#include "mgl2/config.h" +//----------------------------------------------------------------------------- #ifdef WIN32 //_MSC_VER needs this before math.h #define _USE_MATH_DEFINES #endif +#if MGL_HAVE_ZLIB +#include +#ifndef Z_BEST_COMPRESSION +#define Z_BEST_COMPRESSION 9 +#endif +#else +#define gzFile FILE* +#define gzread(fp,buf,size) fread(buf,1,size,fp) +#define gzopen fopen +#define gzclose fclose +#define gzprintf fprintf +#define gzgets(fp,str,size) fgets(str,size,fp) +#define gzgetc fgetc +#endif + #include +#include #include #include +#include + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define fmin(a,b) ((a)<(b))?(a):(b) +#define fmax(a,b) ((a)>(b))?(a):(b) +#endif -#define MGL_VER2 0.0 +#define MGL_VER2 0.3 //#ifdef WIN32 -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__BORLANDC__) #define hypot _hypot #define getcwd _getcwd #define isfinite _finite @@ -58,14 +82,13 @@ const unsigned long mgl_nan[2] = {0xffffffff, 0x7fffffff}; #define mglprintf swprintf #endif //#define FLT_EPS 1.1920928955078125e-07 -#define MGL_FLT_EPS (1.+1e-05) -//----------------------------------------------------------------------------- -#include "mgl2/config.h" //----------------------------------------------------------------------------- #if MGL_USE_DOUBLE typedef double mreal; +#define MGL_EPSILON (1.+1e-10) #else typedef float mreal; +#define MGL_EPSILON (1.+1e-5) #endif //----------------------------------------------------------------------------- #ifndef MGL_CMAP_COLOR @@ -164,13 +187,15 @@ enum{ // Codes for warnings/messages // 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_AUTO_CLF 0x000800 ///< Clear canvas between drawing +#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_HIGHLIGHT 0x004000 ///< Highlight plot +#define MGL_NOSUBTICKS 0x004000 ///< Disable subticks drawing (for bounding box) #define MGL_DIFFUSIVE 0x008000 ///< Use diffusive light instead of specular #define MGL_USEDRWDAT 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_realloc(T,o,no,nn) {T *_tmp = new T[nn]; memcpy(_tmp,o,(no)*sizeof(T)); delete []o; o=_tmp;} //----------------------------------------------------------------------------- @@ -184,12 +209,12 @@ struct mglThreadD void *v; // pointer to data/grapher int id; // thread id long n; // total number of iteration - char *s; + const char *s; }; /// Start several thread for the task void mglStartThread(void *(*func)(void *), void (*post)(mglThreadD *,mreal *), long n, mreal *a=0, const mreal *b=0, const mreal *c=0, const long *p=0, - void *v=0, const mreal *d=0, const mreal *e=0, char *s=0); + void *v=0, const mreal *d=0, const mreal *e=0, const char *s=0); extern int mglNumThr; ///< Number of thread for plotting and data handling //----------------------------------------------------------------------------- extern "C" { @@ -209,6 +234,7 @@ void mgl_strlwr(char *str); #ifdef __cplusplus } #endif +//#if MGL_HAVE_PTHREAD && defined(MGL_SRC) #if MGL_HAVE_PTHREAD #include #define MGL_PUSH(a,v,m) {pthread_mutex_lock(&m); a.push_back(v); pthread_mutex_unlock(&m);} diff --git a/include/mgl2/eval.h b/include/mgl2/eval.h index 7979613..3171c11 100644 --- a/include/mgl2/eval.h +++ b/include/mgl2/eval.h @@ -21,7 +21,6 @@ #ifndef _MGL_EVAL_H_ #define _MGL_EVAL_H_ //--------------------------------------------------------------------------- -#include #include "mgl2/define.h" /// types of errors #define MGL_ERR_LOG 1 diff --git a/include/mgl2/fit.h b/include/mgl2/fit.h index cd5ed0e..5e6b154 100644 --- a/include/mgl2/fit.h +++ b/include/mgl2/fit.h @@ -2,30 +2,30 @@ * fit.h is part of Math Graphic Library * Copyright (C) 2007 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. * - ***************************************************************************/ + * 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_FIT_H_ -#define _MGL_FIT_H_ +#define _MGL_FIT_H_ #include "mgl2/base.h" /*****************************************************************************/ -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -/*****************************************************************************/ -extern int mglFitPnts; ///< Number of output points in fitting +/*****************************************************************************/ +extern int mglFitPnts; ///< Number of output points in fitting extern char mglFitRes[1024]; ///< Last fitted formula HMDT mgl_fit_1(HMGL gr, HCDT y, const char *eq, const char *var, HMDT ini, const char *opt); HMDT mgl_fit_2(HMGL gr, HCDT z, const char *eq, const char *var, HMDT ini, const char *opt); @@ -39,11 +39,12 @@ HMDT mgl_fit_xyzs(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT s, const char *eq, const HMDT mgl_fit_xyzas(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, HCDT s, const char *eq, const char *var, HMDT ini, const char *opt); const char *mgl_get_fit(HMGL gr); - + HMDT mgl_hist_x(HMGL gr, HCDT x, HCDT a, const char *opt); HMDT mgl_hist_xy(HMGL gr, HCDT x, HCDT y, HCDT a, const char *opt); HMDT mgl_hist_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *opt); - + +void mgl_puts_fit(HMGL gr, mreal x, mreal y, mreal z, const char *prefix, const char *font, mreal size); /*****************************************************************************/ uintptr_t mgl_fit_1_(uintptr_t* gr, uintptr_t* y, const char *eq, const char *var, uintptr_t *ini, const char *opt,int, int l, int n); uintptr_t mgl_fit_2_(uintptr_t* gr, uintptr_t* z, const char *eq, const char *var, uintptr_t *ini, const char *opt,int, int l, int n); @@ -55,13 +56,15 @@ uintptr_t mgl_fit_ys_(uintptr_t* gr, uintptr_t* y, uintptr_t* ss, const char *eq uintptr_t mgl_fit_xys_(uintptr_t* gr, uintptr_t* x, uintptr_t* y, uintptr_t* ss, const char *eq, const char *var, uintptr_t *ini, const char *opt,int, int l, int n); uintptr_t mgl_fit_xyzs_(uintptr_t* gr, uintptr_t* x, uintptr_t* y, uintptr_t* z, uintptr_t* ss, const char *eq, const char *var, uintptr_t *ini, const char *opt,int, int l, int n); uintptr_t mgl_fit_xyzas_(uintptr_t* gr, uintptr_t* x, uintptr_t* y, uintptr_t* z, uintptr_t* a, uintptr_t* ss, const char *eq, const char *var, uintptr_t *ini, const char *opt,int, int l, int n); - -uintptr_t mgl_hist_x_(uintptr_t* gr, uintptr_t* x, uintptr_t* a, const char *opt,int); -uintptr_t mgl_hist_xy_(uintptr_t* gr, uintptr_t* x, uintptr_t* y, uintptr_t* a, const char *opt,int); -uintptr_t mgl_hist_xyz_(uintptr_t* gr, uintptr_t* x, uintptr_t* y, uintptr_t* z, uintptr_t* a, const char *opt,int); + +uintptr_t mgl_hist_x_(uintptr_t* gr, uintptr_t* x, uintptr_t* a, const char *opt,int); +uintptr_t mgl_hist_xy_(uintptr_t* gr, uintptr_t* x, uintptr_t* y, uintptr_t* a, const char *opt,int); +uintptr_t mgl_hist_xyz_(uintptr_t* gr, uintptr_t* x, uintptr_t* y, uintptr_t* z, uintptr_t* a, const char *opt,int); + +void mgl_puts_fit_(uintptr_t* gr, mreal *x, mreal *y, mreal *z, const char *prefix, const char *font, mreal *size, int l, int n); /*****************************************************************************/ #ifdef __cplusplus } -#endif +#endif /*****************************************************************************/ -#endif +#endif diff --git a/include/mgl2/fltk.h b/include/mgl2/fltk.h index dcbbbe7..e21016b 100644 --- a/include/mgl2/fltk.h +++ b/include/mgl2/fltk.h @@ -49,7 +49,7 @@ public: /// Update (redraw) plot virtual void update(); /// Set angles for additional plot rotation - inline void set_angle(float t, float p){ tet = t; phi = p; } + inline void set_angle(mreal t, mreal 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 @@ -61,8 +61,7 @@ public: /// Set drawing functions and its parameter inline void set_draw(int (*func)(mglBase *gr, void *par), void *par=0) { draw_func = func; draw_par = par; } - inline void set_draw(mglDraw *dr) - { set_draw(mgl_draw_class,(void*)dr); } + inline void set_draw(mglDraw *dr) { draw_cl = dr; } inline void set_draw(int (*dr)(mglGraph *gr)) { set_draw(mgl_draw_graph,(void*)dr); } void set_state(bool z, bool r) { zoom = z; rotate = r; } @@ -75,7 +74,7 @@ public: /// 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(float xx1,float xx2,float yy1, float yy2) + inline void zoom_region(mreal xx1,mreal xx2,mreal yy1, mreal yy2) { x1=xx1; y1=yy1; x2=xx2; y2=yy2; } protected: @@ -83,21 +82,22 @@ protected: void *draw_par; ///< Parameters for drawing function mglCanvasWnd::DrawFunc. /// Drawing function for window procedure. It should return the number of frames. int (*draw_func)(mglBase *gr, void *par); + mglDraw *draw_cl; const Fl_Menu_Item *popup; ///< pointer to popup menu items Fl_Widget *wpar; ///< widget for popup menu - void *vpar; ///< parameter for popup menu - float tet,phi; ///< rotation angles + void *vpar; ///< parameter for popup menu + mreal tet,phi; ///< rotation angles bool rotate; ///< flag for handle mouse - bool zoom; ///< flag for zoom by mouse + bool zoom; ///< flag for zoom by mouse bool wire; - float x1,x2,y1,y2; ///< zoom region - int flag; ///< bitwise flag for general state (1-Alpha, 2-Light) + mreal 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]; virtual void draw(); ///< quick drawing function - int handle(int code); ///< handle mouse events + int handle(int code); ///< handle mouse events void resize(int x, int y, int w, int h); ///< resize control }; //----------------------------------------------------------------------------- @@ -111,7 +111,7 @@ public: void *par; ///< Parameter for handling animation void (*next)(void*); ///< Callback function for next frame void (*prev)(void*); ///< Callback function for prev frame - float (*delay)(void*); ///< Callback function for delay + mreal (*delay)(void*); ///< Callback function for delay void (*reload)(void*); ///< Callback function for reloading void toggle_alpha() { toggle(alpha, alpha_bt, "Graphics/Alpha"); } @@ -120,7 +120,7 @@ public: void toggle_wire() { toggle(wire, wire_bt, "Graphics/Wire"); } void toggle_zoom() { toggle(zoom, zoom_bt); } void toggle_rotate(){ toggle(rotate, rotate_bt); } - void setoff_zoom() { setoff(zoom,zoom_bt); } + void setoff_zoom() { setoff(zoom, zoom_bt); } void setoff_rotate(){ setoff(rotate, rotate_bt); } bool is_sshow() { return sshow; } diff --git a/include/mgl2/font.h b/include/mgl2/font.h index a095db5..a8b4148 100644 --- a/include/mgl2/font.h +++ b/include/mgl2/font.h @@ -21,7 +21,6 @@ #ifndef _MGL_FONT_H_ #define _MGL_FONT_H_ -#include #include "mgl2/define.h" //----------------------------------------------------------------------------- #define MGL_FONT_BOLD 0x01000000 // This value is used binary diff --git a/include/mgl2/glut.h b/include/mgl2/glut.h index 5b48f32..66b58ed 100644 --- a/include/mgl2/glut.h +++ b/include/mgl2/glut.h @@ -39,7 +39,7 @@ friend void _mgl_display(); friend void _mgl_key_up(unsigned char ch,int ,int ); friend void _mgl_timer(int); public: - float Delay; ///< Delay for animation in seconds + mreal Delay; ///< Delay for animation in seconds bool AutoClf; ///< Clear canvas between drawing mglCanvasGLUT(); diff --git a/include/mgl2/mgl.h b/include/mgl2/mgl.h index 2f1434c..e73cbfa 100644 --- a/include/mgl2/mgl.h +++ b/include/mgl2/mgl.h @@ -23,9 +23,6 @@ #include "mgl2/define.h" #include "mgl2/mgl_cf.h" #include "mgl2/data.h" -#ifndef NO_OPENGL -#include "mgl2/opengl.h" -#endif //----------------------------------------------------------------------------- /// Wrapper class for all graphics class mglGraph @@ -36,10 +33,9 @@ public: inline mglGraph(int kind=0, int width=600, int height=400) { if(kind==-1) gr=NULL; -#ifndef NO_OPENGL - else if(kind==1) gr=mgl_create_graph_gl(); +#if MGL_HAVE_OPENGL + else if(kind==1) gr=mgl_create_graph_gl(); #endif -// else if(kind==2) gr=mgl_create_graph_idtf(); else gr=mgl_create_graph(width, height); } inline mglGraph(const mglGraph &graph) @@ -58,7 +54,7 @@ public: /// Set the transparency on/off. inline void Alpha(bool enable) { mgl_set_alpha(gr, enable); } /// Set default value of alpha-channel - inline void SetAlphaDef(float alpha) { mgl_set_alpha_default(gr, alpha); } + inline void SetAlphaDef(mreal alpha) { mgl_set_alpha_default(gr, alpha); } /// Set the transparency type (0 - usual, 1 - glass, 2 - lamp) inline void SetTranspType(int type) { mgl_set_transp_type(gr, type);} @@ -69,21 +65,21 @@ public: /// Use diffusive light (only for local light sources) inline void SetDifLight(bool dif) { mgl_set_light_dif(gr, dif); } /// Add a light source. - inline void AddLight(int n, mglPoint p, char col='w', float bright=0.5, float ap=0) + inline void AddLight(int n, mglPoint p, char col='w', mreal bright=0.5, mreal ap=0) { mgl_add_light_ext(gr, n, p.x, p.y, p.z, col, bright, ap); } - inline void AddLight(int n, mglPoint r, mglPoint p, char col='w', float bright=0.5, float ap=0) + inline void AddLight(int n, mglPoint r, mglPoint p, char col='w', mreal bright=0.5, mreal ap=0) { mgl_add_light_loc(gr, n, r.x, r.y, r.z, p.x, p.y, p.z, col, bright, ap); } /// Set ambient light brightness - inline void SetAmbient(float i) { mgl_set_ambbr(gr, i); } + inline void SetAmbient(mreal i) { mgl_set_ambbr(gr, i); } /// Set the fog distance or switch it off (if d=0). - inline void Fog(float d, float dz=0.25) { mgl_set_fog(gr, d, dz); } + inline void Fog(mreal d, mreal dz=0.25) { mgl_set_fog(gr, d, dz); } /// Set relative width of rectangles in Bars, Barh, BoxPlot - inline void SetBarWidth(float width) { mgl_set_bar_width(gr, width); } + inline void SetBarWidth(mreal width) { mgl_set_bar_width(gr, width); } /// Set size of marks - inline void SetMarkSize(float size) { mgl_set_mark_size(gr, size); } + inline void SetMarkSize(mreal size) { mgl_set_mark_size(gr, size); } /// Set size of arrows - inline void SetArrowSize(float size) { mgl_set_arrow_size(gr, size); } + inline void SetArrowSize(mreal size) { mgl_set_arrow_size(gr, size); } /// Set number of mesh lines inline void SetMeshNum(int num) { mgl_set_meshnum(gr, num); } @@ -96,15 +92,15 @@ public: inline void CutOff(const char *EqC) { mgl_set_cutoff(gr, EqC); } /// Set default font size - inline void SetFontSize(float size) { mgl_set_font_size(gr, size); } + inline void SetFontSize(mreal 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) - virtual void SetFontSizePT(float pt, int dpi=72){ SetFontSize(pt*27.f/dpi); } + virtual void SetFontSizePT(mreal 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(float cm, int dpi=72) { SetFontSizePT(cm*28.45f,dpi); } + inline void SetFontSizeCM(mreal 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) - inline void SetFontSizeIN(float in, int dpi=72) { SetFontSizePT(in*72.27f,dpi); } + inline void SetFontSizeIN(mreal in, int dpi=72) { SetFontSizePT(in*72.27f,dpi); } /// Load font from file inline void LoadFont(const char *name, const char *path=NULL) { mgl_load_font(gr, name, path); } @@ -123,29 +119,29 @@ public: /// Get last warning code inline int GetWarn() { return mgl_get_warn(gr);} /// Set warning code ant fill message - inline void SetWarn(int code, const char *info="") { mgl_set_warn(gr,code,info); } + inline void SetWarn(int code, const char *info) { mgl_set_warn(gr,code,info); } /// Set buffer for warning messages inline const char *Message() { return mgl_get_mess(gr); } /// Set range in direction dir as [v1, v2] - inline void SetRange(char dir, float v1, float v2) + inline void SetRange(char dir, mreal v1, mreal v2) { mgl_set_range_val(gr, dir, v1, v2); } /// Set range in direction dir as minimal and maximal values of data a inline void SetRange(char dir, const mglDataA &dat, bool add=false) { mgl_set_range_dat(gr, dir, &dat, add); } /// Set values of mglGraph::Min and mglGraph::Max as minimal and maximal values of datas - inline void SetRanges(const mglData &xx, const mglData &yy, const mglData &zz, const mglData &cc) + inline void SetRanges(const mglDataA &xx, const mglDataA &yy, const mglDataA &zz, const mglDataA &cc) { mgl_set_range_dat(gr,'x',&xx,0); mgl_set_range_dat(gr,'y',&yy,0); mgl_set_range_dat(gr,'z',&zz,0); mgl_set_range_dat(gr,'c',&cc,0); } /// Set values of mglGraph::Min and mglGraph::Max as minimal and maximal values of datas - inline void SetRanges(const mglData &xx, const mglData &yy, const mglData &zz) + inline void SetRanges(const mglDataA &xx, const mglDataA &yy, const mglDataA &zz) { mgl_set_range_dat(gr,'x',&xx,0); mgl_set_range_dat(gr,'y',&yy,0); mgl_set_range_dat(gr,'z',&zz,0); mgl_set_range_dat(gr,'c',&zz,0); } /// Set values of mglGraph::Min and mglGraph::Max as minimal and maximal values of datas - inline void SetRanges(const mglData &xx, const mglData &yy) + inline void SetRanges(const mglDataA &xx, const mglDataA &yy) { mgl_set_range_dat(gr,'x',&xx,0); mgl_set_range_dat(gr,'y',&yy,0); } /// Set values of mglGraph::Min and mglGraph::Max - inline void SetRanges(float x1, float x2, float y1, float y2, float z1=0, float z2=0) + inline void SetRanges(mreal x1, mreal x2, mreal y1, mreal y2, mreal z1=0, mreal z2=0) { mgl_set_ranges(gr, x1, x2, y1, y2, z1, z2); } /// Set values of mglGraph::Min and mglGraph::Max inline void SetRanges(mglPoint p1, mglPoint p2) @@ -153,7 +149,7 @@ public: /// Set axis origin inline void SetOrigin(mglPoint p) { mgl_set_origin(gr, p.x, p.y, p.z); } - inline void SetOrigin(float x0, float y0, float z0=NaN) + inline void SetOrigin(mreal x0, mreal y0, mreal z0=NaN) { mgl_set_origin(gr, x0, y0, z0); } /// Set the transformation formulas for coordinate @@ -169,14 +165,14 @@ public: /// Set to use or not tick labels skipping inline void SetTickSkip(bool val) { mgl_set_tick_skip(gr,val); } /// Set tick length - inline void SetTickLen(float len, float stt=1) + inline void SetTickLen(mreal len, mreal stt=1) { mgl_set_tick_len(gr, len, stt); } /// Set axis and ticks style inline void SetAxisStl(const char *stl="k", const char *tck=0, const char *sub=0) { mgl_set_axis_stl(gr, stl, tck, sub); } /// Set time templates for ticks - inline void SetTicksTime(char dir, float d=0, const char *t="") + inline void SetTicksTime(char dir, mreal d=0, const char *t="") { mgl_set_ticks_time(gr,dir,d,t); } /// Set ticks text (\n separated). Use "" to disable this feature. inline void SetTicksVal(char dir, const char *lbl, bool add=false) @@ -189,7 +185,7 @@ public: inline void SetTicksVal(char dir, const mglDataA &v, const wchar_t *lbl, bool add=false) { mgl_set_ticks_valw(gr,dir,&v,lbl,add); } /// Set the ticks parameters - inline void SetTicks(char dir, float d=0, int ns=0, float org=NaN) + inline void SetTicks(char dir, mreal d=0, int ns=0, mreal org=NaN) { mgl_set_ticks(gr, dir, d, ns, org); } /// Auto adjust ticks inline void Adjust(const char *dir="xyzc") @@ -200,31 +196,37 @@ public: inline void SetTickTempl(char dir, const wchar_t *t) { mgl_set_tick_templw(gr,dir,t); } /// Tune ticks - inline void SetTuneTicks(int tune, float fact_pos=1.15) + inline void SetTuneTicks(int tune, mreal fact_pos=1.15) { mgl_tune_ticks(gr, tune, fact_pos); } - + /// Set additional shift of tick labels + inline void SetTickShift(mglPoint p) + { mgl_set_tick_shift(gr,p.x,p.y,p.z,p.c); } + /// Set to use UTC time instead of local time + inline void SetTimeUTC(bool enable) + { mgl_set_flag(gr,enable, MGL_USE_GMTIME); } + /// Put further plotting in some region of whole frame surface. - inline void SubPlot(int nx,int ny,int m,const char *style="<>_^", float dx=0, float dy=0) + inline void SubPlot(int nx,int ny,int m,const char *style="<>_^", mreal dx=0, mreal dy=0) { mgl_subplot_d(gr, nx, ny, m, style, dx, dy); } /// Like SubPlot bot "join" several cells 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); } /// Put further plotting in some region of whole frame surface. - inline void InPlot(float x1,float x2,float y1,float y2, bool rel=true) + inline void InPlot(mreal x1,mreal x2,mreal y1,mreal y2, bool rel=true) { if(rel) mgl_relplot(gr, x1, x2, y1, y2); else mgl_inplot(gr, x1, x2, y1, y2); } /// Put further plotting in column cell of previous subplot - inline void ColumnPlot(int num, int ind, float d=0) + inline void ColumnPlot(int num, int ind, mreal d=0) { mgl_columnplot(gr,num,ind,d); } /// Put further plotting in matrix cell of previous subplot - inline void GridPlot(int nx, int ny, int ind, float d=0) + inline void GridPlot(int nx, int ny, int ind, mreal d=0) { mgl_gridplot(gr,nx,ny,ind,d); } /// Put further plotting in cell of stick rotated on angles tet, phi - inline void StickPlot(int num, int i, float tet, float phi) + inline void StickPlot(int num, int i, mreal tet, mreal phi) { mgl_stickplot(gr,num,i,tet,phi); } /// Set PlotFactor - inline void SetPlotFactor(float val) + inline void SetPlotFactor(mreal val) { mgl_set_plotfactor(gr,val); } /// Push transformation matrix into stack inline void Push() { mgl_mat_push(gr); } @@ -232,27 +234,27 @@ public: inline void Pop() { mgl_mat_pop(gr); } /// Add title for current subplot/inplot - inline void Title(const char *title,const char *stl="",float size=-2) + inline void Title(const char *title,const char *stl="",mreal size=-2) { mgl_title(gr,title,stl,size); } - inline void Title(const wchar_t *title,const char *stl="",float size=-2) + inline void Title(const wchar_t *title,const char *stl="",mreal size=-2) { mgl_titlew(gr,title,stl,size); } /// Set aspect ratio for further plotting. - inline void Aspect(float Ax,float Ay,float Az=1) + inline void Aspect(mreal Ax,mreal Ay,mreal Az=1) { mgl_aspect(gr, Ax, Ay, Az); } /// Rotate a further plotting. - inline void Rotate(float TetX,float TetZ=0,float TetY=0) + inline void Rotate(mreal TetX,mreal TetZ=0,mreal TetY=0) { mgl_rotate(gr, TetX, TetZ, TetY); } /// Rotate a further plotting around vector {x,y,z}. - inline void RotateN(float Tet,float x,float y,float z) + inline void RotateN(mreal Tet,mreal x,mreal y,mreal z) { mgl_rotate_vector(gr, Tet, x, y, z); } /// Set perspective (in range [0,1)) for plot. Set to zero for switching off. - inline void Perspective(float val) + inline void Perspective(mreal val) { mgl_perspective(gr, val); } /// Set angle of view independently from Rotate(). - inline void View(float TetX,float TetZ=0,float TetY=0) + inline void View(mreal TetX,mreal TetZ=0,mreal TetY=0) { mgl_view(gr, TetX, TetZ, TetY); } /// Zoom in or zoom out (if Zoom(0, 0, 1, 1)) a part of picture - inline void Zoom(float x1, float y1, float x2, float y2) + inline void Zoom(mreal x1, mreal y1, mreal x2, mreal y2) { mgl_zoom(gr, x1, y1, x2, y2); } /// Set size of frame in pixels. Normally this function is called internaly. @@ -288,7 +290,7 @@ public: /// Write the frame in file using PostScript format inline void WriteEPS(const char *fname,const char *descr="") { mgl_write_eps(gr, fname, descr); } - /// Write the frame in file using PostScript format + /// Write the frame in file using LaTeX format inline void WriteTEX(const char *fname,const char *descr="") { mgl_write_tex(gr, fname, descr); } /// Write the frame in file using PostScript format as bitmap @@ -374,7 +376,7 @@ public: /// Calculate 3D coordinate {x,y,z} for screen point {xs,ys} inline mglPoint CalcXYZ(int xs, int ys) { - float x,y,z; + mreal x,y,z; mgl_calc_xyz(gr,xs,ys,&x,&y,&z); return mglPoint(x,y,z); } @@ -400,7 +402,7 @@ public: inline void MPI_Recv(int id) { mgl_mpi_recv(gr,id); } /// Clear up the frame - inline void Clf(float r, float g, float b) { mgl_clf_rgb(gr, r, g, b); } + inline void Clf(mreal r, mreal g, mreal b) { mgl_clf_rgb(gr, r, g, b); } inline void Clf() { mgl_clf(gr); } /// Draws the point (ball) at position {x,y,z} with color c inline void Ball(mglPoint p, char c) @@ -422,46 +424,46 @@ public: 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); } /// Draws the face in y-z plane at point p with color stl (include interpolation up to 4 colors). - inline void FaceX(mglPoint p, float wy, float wz, const char *stl="w", float dx=0, float dy=0) + inline void FaceX(mglPoint p, mreal wy, mreal wz, const char *stl="w", mreal dx=0, mreal dy=0) { mgl_facex(gr, p.x, p.y, p.z, wy, wz, stl, dx, dy); } /// Draws the face in x-z plane at point p with color stl (include interpolation up to 4 colors). - inline void FaceY(mglPoint p, float wx, float wz, const char *stl="w", float dx=0, float dy=0) + inline void FaceY(mglPoint p, mreal wx, mreal wz, const char *stl="w", mreal dx=0, mreal dy=0) { mgl_facey(gr, p.x, p.y, p.z, wx, wz, stl, dx, dy); } /// Draws the face in x-y plane at point p with color stl (include interpolation up to 4 colors). - inline void FaceZ(mglPoint p, float wx, float wy, const char *stl="w", float dx=0, float dy=0) + inline void FaceZ(mglPoint p, mreal wx, mreal wy, const char *stl="w", mreal dx=0, mreal dy=0) { mgl_facez(gr, p.x, p.y, p.z, wx, wy, stl, dx, dy); } /// Draws the drop at point p in direction d with color col and radius r - inline void Drop(mglPoint p, mglPoint d, float r, const char *col="r", float shift=1, float ap=1) + inline void Drop(mglPoint p, mglPoint d, mreal r, const char *col="r", mreal shift=1, mreal ap=1) { mgl_drop(gr, p.x, p.y, p.z, d.x, d.y, d.z, r, col, shift, ap); } /// Draws the sphere at point p with color col and radius r - inline void Sphere(mglPoint p, float r, const char *col="r") + inline void Sphere(mglPoint p, mreal r, const char *col="r") { mgl_sphere(gr, p.x, p.y, p.z, r, col); } /// Draws the cone between points p1,p2 with radius r1,r2 with style stl - inline void Cone(mglPoint p1, mglPoint p2, float r1, float r2=-1, const char *stl="r@") + inline void Cone(mglPoint p1, mglPoint p2, mreal r1, mreal r2=-1, const char *stl="r@") { mgl_cone(gr, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z,r1,r2,stl); } /// Draws the ellipse between points p1,p2 with color stl and width r - inline void Ellipse(mglPoint p1, mglPoint p2, float r, const char *stl="r") + inline void Ellipse(mglPoint p1, mglPoint p2, mreal r, const char *stl="r") { mgl_ellipse(gr, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, r,stl); } /// Draws the circle at point p with color stl and radius r - inline void Circle(mglPoint p, float r, const char *stl="r") + inline void Circle(mglPoint p, mreal r, const char *stl="r") { mgl_ellipse(gr, p.x, p.y, p.z, p.x, p.y, p.z, r,stl); } /// Draws the rhomb between points p1,p2 with color stl and width r - inline void Rhomb(mglPoint p1, mglPoint p2, float r, const char *stl="r") + inline void Rhomb(mglPoint p1, mglPoint p2, mreal r, const char *stl="r") { mgl_rhomb(gr, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, r,stl); } /// Print text in position p with specified font - inline void Putsw(mglPoint p,const wchar_t *text,const char *font=":C",float size=-1) + inline void Putsw(mglPoint p,const wchar_t *text,const char *font=":C",mreal size=-1) { mgl_putsw(gr, p.x, p.y, p.z, text, font, size); } - inline void Puts(mglPoint p,const char *text,const char *font=":C",float size=-1) + inline void Puts(mglPoint p,const char *text,const char *font=":C",mreal size=-1) { mgl_puts(gr, p.x, p.y, p.z, text, font, size); } - inline void Putsw(float x, float y,const wchar_t *text,const char *font=":AC",float size=-1) + inline void Putsw(mreal x, mreal y,const wchar_t *text,const char *font=":AC",mreal size=-1) { mgl_putsw(gr, x, y, 0, text, font, size); } - inline void Puts(float x, float y,const char *text,const char *font=":AC",float size=-1) + inline void Puts(mreal x, mreal y,const char *text,const char *font=":AC",mreal size=-1) { mgl_puts(gr, x, y, 0, text, font, size); } /// Print text in position p along direction d with specified font - inline void Putsw(mglPoint p, mglPoint d, const wchar_t *text, const char *font=":L", float size=-1) + inline void Putsw(mglPoint p, mglPoint d, const wchar_t *text, const char *font=":L", mreal size=-1) { mgl_putsw_dir(gr, p.x, p.y, p.z, d.x, d.y, d.z, text, font, size); } - inline void Puts(mglPoint p, mglPoint d, const char *text, const char *font=":L", float size=-1) + inline void Puts(mglPoint p, mglPoint d, const char *text, const char *font=":L", mreal size=-1) { mgl_puts_dir(gr, p.x, p.y, p.z, d.x, d.y, d.z, text, font, size); } /// Print text along the curve @@ -488,20 +490,20 @@ public: inline void Grid(const char *dir="xyzt",const char *pen="B") { mgl_axis_grid(gr, dir, pen); } /// Print the label \a text for axis \a dir. - inline void Label(char dir, const char *text, float pos=+1, float shift=0) + inline void Label(char dir, const char *text, mreal pos=+1, mreal shift=0) { mgl_label_ext(gr, dir, text, pos, shift); } - inline void Label(char dir, const wchar_t *text, float pos=+1, float shift=0) + inline void Label(char dir, const wchar_t *text, mreal pos=+1, mreal shift=0) { mgl_labelw_ext(gr, dir, text, pos, shift); } /// Draw colorbar at edge of axis inline void Colorbar(const char *sch="") { mgl_colorbar(gr, sch); } - inline void Colorbar(const char *sch,float x,float y,float w=1,float h=1) + inline void Colorbar(const char *sch,mreal x,mreal y,mreal w=1,mreal h=1) { mgl_colorbar_ext(gr, sch, x,y,w,h); } /// Draw colorbar with manual colors at edge of axis inline void Colorbar(const mglDataA &val, const char *sch="") { mgl_colorbar_val(gr, &val, sch); } - inline void Colorbar(const mglDataA &val, const char *sch,float x,float y,float w=1,float h=1) + inline void Colorbar(const mglDataA &val, const char *sch,mreal x,mreal y,mreal w=1,mreal h=1) { mgl_colorbar_val_ext(gr, &val, sch, x,y,w,h); } /// Add string to legend @@ -513,10 +515,10 @@ public: inline void ClearLegend() { mgl_clear_legend(gr); } /// Draw legend of accumulated strings at position {x,y} - inline void Legend(float x, float y, const char *font="#", float size=-0.8, float llen=0) + inline void Legend(mreal x, mreal y, const char *font="#", mreal size=-0.8, mreal llen=0) { mgl_legend_pos(gr, x, y, font, size, llen); } /// Draw legend of accumulated strings - inline void Legend(int where=3, const char *font="#", float size=-0.8, float llen=0) + inline void Legend(int where=3, const char *font="#", mreal size=-0.8, mreal llen=0) { mgl_legend(gr, where, font, size, llen); } /// Set number of marks in legend sample inline void SetLegendMarks(int num) { mgl_set_legend_marks(gr, num); } @@ -660,15 +662,15 @@ public: /// Draw tube with radius r for points in arrays {x,y,z} inline void Tube(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &r, const char *pen="", const char *opt="") { mgl_tube_xyzr(gr, &x, &y, &z, &r, pen, opt); } - inline void Tube(const mglDataA &x, const mglDataA &y, const mglDataA &z, float r, const char *pen="", const char *opt="") + inline void Tube(const mglDataA &x, const mglDataA &y, const mglDataA &z, mreal r, const char *pen="", const char *opt="") { mgl_tube_xyz(gr, &x, &y, &z, r, pen, opt); } inline void Tube(const mglDataA &x, const mglDataA &y, const mglDataA &r, const char *pen="", const char *opt="") { mgl_tube_xyr(gr, &x, &y, &r, pen, opt); } - inline void Tube(const mglDataA &x, const mglDataA &y, float r, const char *pen="", const char *opt="") + inline void Tube(const mglDataA &x, const mglDataA &y, mreal r, const char *pen="", const char *opt="") { mgl_tube_xy(gr, &x, &y, r, pen, opt); } inline void Tube(const mglDataA &y, const mglDataA &r, const char *pen="", const char *opt="") { mgl_tube_r(gr, &y, &r, pen, opt); } - inline void Tube(const mglDataA &y, float r, const char *pen="", const char *opt="") + inline void Tube(const mglDataA &y, mreal r, const char *pen="", const char *opt="") { mgl_tube(gr, &y, r, pen, opt); } /// Draw surface of curve {r,z} rotatation around axis inline void Torus(const mglDataA &r, const mglDataA &z, const char *pen="", const char *opt="") @@ -762,20 +764,20 @@ public: { mgl_axial(gr, &z, sch, opt); } /// Draw grid lines for density plot at slice for 3d data specified parametrically - inline void Grid3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *stl="", float sVal=-1, const char *opt="") + inline void Grid3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *stl="", mreal sVal=-1, const char *opt="") { mgl_grid3_xyz(gr, &x, &y, &z, &a, stl, sVal, opt); } - inline void Grid3(const mglDataA &a, const char *stl="", float sVal=-1, const char *opt="") + inline void Grid3(const mglDataA &a, const char *stl="", mreal sVal=-1, const char *opt="") { mgl_grid3(gr, &a, stl, sVal, opt); } /// Draw density plot at slice for 3d data specified parametrically - inline void Dens3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *stl="", float sVal=-1, const char *opt="") + inline void Dens3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *stl="", mreal sVal=-1, const char *opt="") { mgl_dens3_xyz(gr, &x, &y, &z, &a, stl, sVal, opt); } - inline void Dens3(const mglDataA &a, const char *stl="", float sVal=-1, const char *opt="") + inline void Dens3(const mglDataA &a, const char *stl="", mreal sVal=-1, const char *opt="") { mgl_dens3(gr, &a, stl, sVal, opt); } /// Draw isosurface(s) for 3d data specified parametrically - inline void Surf3(float Val, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *stl="", const char *opt="") + inline void Surf3(mreal Val, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *stl="", const char *opt="") { mgl_surf3_xyz_val(gr, Val, &x, &y, &z, &a, stl, opt); } - inline void Surf3(float Val, const mglDataA &a, const char *stl="", const char *opt="") + inline void Surf3(mreal Val, const mglDataA &a, const char *stl="", const char *opt="") { mgl_surf3_val(gr, Val, &a, stl, opt); } inline void Surf3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *stl="", const char *opt="") { mgl_surf3_xyz(gr, &x, &y, &z, &a, stl, opt); } @@ -789,29 +791,29 @@ public: { mgl_cloud(gr, &a, stl, opt); } /// Draw contour lines at slice for 3d data specified parametrically - inline void Cont3(const mglDataA &v, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", float sVal=-1, const char *opt="") + inline void Cont3(const mglDataA &v, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", mreal sVal=-1, const char *opt="") { mgl_cont3_xyz_val(gr, &v, &x, &y, &z, &a, sch, sVal, opt); } - inline void Cont3(const mglDataA &v, const mglDataA &a, const char *sch="", float sVal=-1, const char *opt="") + inline void Cont3(const mglDataA &v, const mglDataA &a, const char *sch="", mreal sVal=-1, const char *opt="") { mgl_cont3_val(gr, &v, &a, sch, sVal, opt); } - inline void Cont3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", float sVal=-1, const char *opt="") + inline void Cont3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", mreal sVal=-1, const char *opt="") { mgl_cont3_xyz(gr, &x, &y, &z, &a, sch, sVal, opt); } - inline void Cont3(const mglDataA &a, const char *sch="", float sVal=-1, const char *opt="") + inline void Cont3(const mglDataA &a, const char *sch="", mreal sVal=-1, const char *opt="") { mgl_cont3(gr, &a, sch, sVal, opt); } /// Draw solid contours at slice for 3d data specified parametrically - inline void ContF3(const mglDataA &v, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", float sVal=-1, const char *opt="") + inline void ContF3(const mglDataA &v, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", mreal sVal=-1, const char *opt="") { mgl_contf3_xyz_val(gr, &v, &x, &y, &z, &a, sch, sVal, opt); } - inline void ContF3(const mglDataA &v, const mglDataA &a, const char *sch="", float sVal=-1, const char *opt="") + inline void ContF3(const mglDataA &v, const mglDataA &a, const char *sch="", mreal sVal=-1, const char *opt="") { mgl_contf3_val(gr, &v, &a, sch, sVal, opt); } - inline void ContF3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", float sVal=-1, const char *opt="") + inline void ContF3(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const char *sch="", mreal sVal=-1, const char *opt="") { mgl_contf3_xyz(gr, &x, &y, &z, &a, sch, sVal, opt); } - inline void ContF3(const mglDataA &a, const char *sch="", float sVal=-1, const char *opt="") + inline void ContF3(const mglDataA &a, const char *sch="", mreal sVal=-1, const char *opt="") { mgl_contf3(gr, &a, sch, sVal, opt); } /// Draw several isosurfaces for 3d beam in curvilinear coordinates - inline void Beam(const mglDataA &tr, const mglDataA &g1, const mglDataA &g2, const mglDataA &a, float r, const char *stl=0, int flag=0, int num=3) + inline void Beam(const mglDataA &tr, const mglDataA &g1, const mglDataA &g2, const mglDataA &a, mreal r, const char *stl=0, int flag=0, int num=3) { mgl_beam(gr, &tr,&g1,&g2,&a,r,stl,flag,num); } - inline void Beam(float val, const mglDataA &tr, const mglDataA &g1, const mglDataA &g2, const mglDataA &a, float r, const char *stl=NULL, int flag=0) + inline void Beam(mreal val, const mglDataA &tr, const mglDataA &g1, const mglDataA &g2, const mglDataA &a, mreal 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 for 2d data specified parametrically @@ -841,18 +843,18 @@ public: { mgl_stfa(gr, &re, &im, dn, sch, opt); } /// Draw isosurface(s) for 3d data specified parametrically with alpha proportional to b - inline void Surf3A(float Val, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") + inline void Surf3A(mreal Val, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") { mgl_surf3a_xyz_val(gr, Val, &x, &y, &z, &a, &b, stl, opt); } - inline void Surf3A(float Val, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") + inline void Surf3A(mreal Val, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") { mgl_surf3a_val(gr, Val, &a, &b, stl, opt); } inline void Surf3A(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") { mgl_surf3a_xyz(gr, &x, &y, &z, &a, &b, stl, opt); } inline void Surf3A(const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") { mgl_surf3a(gr, &a, &b, stl, opt); } /// Draw isosurface(s) for 3d data specified parametrically with color proportional to b - inline void Surf3C(float Val, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") + inline void Surf3C(mreal Val, const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") { mgl_surf3c_xyz_val(gr, Val, &x, &y, &z, &a, &b, stl,opt); } - inline void Surf3C(float Val, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") + inline void Surf3C(mreal Val, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") { mgl_surf3c_val(gr, Val, &a, &b, stl, opt); } inline void Surf3C(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const mglDataA &b, const char *stl="", const char *opt="") { mgl_surf3c_xyz(gr, &x, &y, &z, &a, &b, stl, opt); } @@ -907,53 +909,53 @@ public: { mgl_grad(gr,&phi,sch,opt); } /// Plot flow pipes for vector field {ax,ay,ay} parametrically depended on coordinate {x,y,z} with color proportional to |a| - inline void Pipe(const mglDataA &x, const mglDataA &y, const mglDataA &ax, const mglDataA &ay, const char *sch="", float r0=0.05, const char *opt="") + inline void Pipe(const mglDataA &x, const mglDataA &y, const mglDataA &ax, const mglDataA &ay, const char *sch="", mreal r0=0.05, const char *opt="") { mgl_pipe_xy(gr, &x, &y, &ax, &ay, sch, r0, opt); } - inline void Pipe(const mglDataA &ax, const mglDataA &ay, const char *sch="", float r0=0.05, const char *opt="") + inline void Pipe(const mglDataA &ax, const mglDataA &ay, const char *sch="", mreal r0=0.05, const char *opt="") { mgl_pipe_2d(gr, &ax, &ay, sch, r0, opt); } - inline void Pipe(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &ax, const mglDataA &ay, const mglDataA &az, const char *sch="", float r0=0.05, const char *opt="") + inline void Pipe(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &ax, const mglDataA &ay, const mglDataA &az, const char *sch="", mreal r0=0.05, const char *opt="") { mgl_pipe_xyz(gr, &x, &y, &z, &ax, &ay, &az, sch, r0, opt); } - inline void Pipe(const mglDataA &ax, const mglDataA &ay, const mglDataA &az, const char *sch="", float r0=0.05, const char *opt="") + inline void Pipe(const mglDataA &ax, const mglDataA &ay, const mglDataA &az, const char *sch="", mreal r0=0.05, const char *opt="") { mgl_pipe_3d(gr, &ax, &ay, &az, sch, r0, opt); } /// Draw density plot for data at x = sVal - inline void DensX(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void DensX(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_dens_x(gr, &a, stl, sVal, opt); } /// Draw density plot for data at y = sVal - inline void DensY(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void DensY(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_dens_y(gr, &a, stl, sVal, opt); } /// Draw density plot for data at z = sVal - inline void DensZ(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void DensZ(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_dens_z(gr, &a, stl, sVal, opt); } /// Draw contour plots for data at x = sVal - inline void ContX(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContX(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_cont_x(gr, &a, stl, sVal, opt); } - inline void ContX(const mglDataA &v, const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContX(const mglDataA &v, const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_cont_x_val(gr, &v, &a, stl, sVal, opt); } /// Draw contour plots for data at y = sVal - inline void ContY(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContY(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_cont_y(gr, &a, stl, sVal, opt); } - inline void ContY(const mglDataA &v, const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContY(const mglDataA &v, const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_cont_y_val(gr, &v, &a, stl, sVal, opt); } /// Draw contour plots for data at z = sVal - inline void ContZ(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContZ(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_cont_z(gr, &a, stl, sVal, opt); } - inline void ContZ(const mglDataA &v, const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContZ(const mglDataA &v, const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_cont_z_val(gr, &v, &a, stl, sVal, opt); } /// Draw solid contour plots for data at x = sVal - inline void ContFX(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContFX(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_contf_x(gr, &a, stl, sVal, opt); } - inline void ContFX(const mglDataA &v, const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContFX(const mglDataA &v, const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_contf_x_val(gr, &v, &a, stl, sVal, opt); } /// Draw solid contour plots for data at y = sVal - inline void ContFY(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContFY(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_contf_y(gr, &a, stl, sVal, opt); } - inline void ContFY(const mglDataA &v, const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContFY(const mglDataA &v, const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_contf_y_val(gr, &v, &a, stl, sVal, opt); } /// Draw solid contour plots for data at z = sVal - inline void ContFZ(const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContFZ(const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_contf_z(gr, &a, stl, sVal, opt); } - inline void ContFZ(const mglDataA &v, const mglDataA &a, const char *stl="", float sVal=NaN, const char *opt="") + inline void ContFZ(const mglDataA &v, const mglDataA &a, const char *stl="", mreal sVal=NaN, const char *opt="") { mgl_contf_z_val(gr, &v, &a, stl, sVal, opt); } /// Draw curve for formula with x in range [Min.x, Max.x] @@ -1054,14 +1056,14 @@ public: inline mglData FitS(const mglDataA &x, const mglDataA &y, const mglDataA &z, const mglDataA &a, const mglDataA &s, const char *eq, const char *var, mglData &ini, const char *opt="") { return mglData(true,mgl_fit_xyzas(gr, &x, &y, &z, &a, &s, eq, var, &ini, opt)); } /// Print fitted last formula (with coefficients) - inline void PutsFit(mglPoint p, const char *prefix=0, const char *font=0, float size=-1) + inline void PutsFit(mglPoint p, const char *prefix=0, const char *font=0, mreal size=-1) { mgl_puts_fit(gr, p.x, p.y, p.z, prefix, font, size); } /// Get last fitted formula inline const char *GetFit() { return mgl_get_fit(gr); } /// Solve PDE with x,y,z in range [Min, Max] - inline mglData PDE(const char *ham, const mglDataA &ini_re, const mglDataA &ini_im, float dz=0.1, float k0=100, const char *opt="") + inline mglData PDE(const char *ham, const mglDataA &ini_re, const mglDataA &ini_im, mreal dz=0.1, mreal k0=100, const char *opt="") { return mglData(true,mgl_pde_solve(gr,ham,&ini_re,&ini_im,dz,k0, opt)); } /// Fill data by formula with x,y,z in range [Min, Max] inline void Fill(mglData &u, const char *eq, const char *opt="") @@ -1071,6 +1073,10 @@ public: inline void Fill(mglData &u, const char *eq, const mglDataA &v, const mglDataA &w, const char *opt="") { mgl_data_fill_eq(gr, &u, eq, &v, &w, opt); } + /// Set the data by triangulated surface values assuming x,y,z in range [Min, Max] + inline void DataGrid(mglData &d, const mglDataA &x, const mglDataA &y, const mglDataA &z, const char *opt="") + { mgl_data_grid(gr,&d,&x,&y,&z,opt); } + /// Make histogram (distribution) of data. This function do not plot data. inline mglData Hist(const mglDataA &x, const mglDataA &a, const char *opt="") { return mglData(true, mgl_hist_x(gr, &x, &a, opt)); } @@ -1080,8 +1086,10 @@ public: { return mglData(true, mgl_hist_xyz(gr, &x, &y, &z, &a, opt)); } inline void Compression(bool){} // NOTE: Add later -- IDTF - inline void VertexColor(bool){} // NOTE: Add later -- IDTF - inline void DoubleSided(bool){} // NOTE: Add later -- IDTF + /// Set the preference for vertex color on/off (for formats that support it, now only PRC does). + inline void VertexColor(bool enable) { mgl_set_flag(gr,enable, MGL_PREFERVC); } + /// Render only front side of surfaces for dubugging purposes (for formats that support it, now only PRC does). + inline void DoubleSided(bool enable) { mgl_set_flag(gr,!enable, MGL_ONESIDED); } inline void TextureColor(bool){} // NOTE: Add later -- IDTF }; //----------------------------------------------------------------------------- diff --git a/include/mgl2/mgl_cf.h b/include/mgl2/mgl_cf.h index 768a973..e102c38 100644 --- a/include/mgl2/mgl_cf.h +++ b/include/mgl2/mgl_cf.h @@ -33,4 +33,15 @@ #include "mgl2/canvas_cf.h" #include "mgl2/addon.h" /*****************************************************************************/ +#if MGL_HAVE_OPENGL +#ifdef __cplusplus +extern "C" { +#endif +HMGL mgl_create_graph_gl(); +uintptr_t mgl_create_graph_gl_(); +#ifdef __cplusplus +} +#endif +#endif +/*****************************************************************************/ #endif diff --git a/include/mgl2/opengl.h b/include/mgl2/opengl.h index fcb7624..ca712e6 100644 --- a/include/mgl2/opengl.h +++ b/include/mgl2/opengl.h @@ -32,15 +32,15 @@ public: void SetQuality(int =0) { Quality=2; } void Finish(bool fast=true); void SetSize(int ,int ) {} - void View(float tetX,float tetY,float tetZ); + void View(mreal tetX,mreal tetY,mreal tetZ); int NewFrame(); void EndFrame(); bool Alpha(bool enable); - void Fog(float d, float dz=0.25); + void Fog(mreal d, mreal dz=0.25); bool Light(bool enable); void Light(int n, bool enable); - void AddLight(int n,mglPoint r,mglPoint d, char c='w', float bright=0.5, float ap=0); + void AddLight(int n,mglPoint r,mglPoint d, char c='w', mreal bright=0.5, mreal ap=0); void Clf(mglColor Back=WC); protected: @@ -51,7 +51,7 @@ protected: unsigned char **GetRGBLines(long &w, long &h, unsigned char *&f, bool solid=true); void LightScale(); - void set_pen(unsigned style,float width); + void set_pen(unsigned style,mreal width); }; extern "C" { #endif diff --git a/include/mgl2/other.h b/include/mgl2/other.h index 835379e..b31122f 100644 --- a/include/mgl2/other.h +++ b/include/mgl2/other.h @@ -2,67 +2,67 @@ * other.h is part of Math Graphic Library * Copyright (C) 2007 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. * - ***************************************************************************/ + * 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_OTHER_H_ -#define _MGL_OTHER_H_ +#define _MGL_OTHER_H_ #include "mgl2/base.h" /*****************************************************************************/ -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif /*****************************************************************************/ void mgl_triplot_xyzc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, const char *opt); void mgl_triplot_xyz(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt); void mgl_triplot_xy(HMGL gr, HCDT nums, HCDT x, HCDT y, const char *sch, const char *opt); - + void mgl_quadplot_xyzc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, const char *opt); void mgl_quadplot_xyz(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt); void mgl_quadplot_xy(HMGL gr, HCDT nums, HCDT x, HCDT y, const char *sch, const char *opt); - + void mgl_tricont_xyzcv(HMGL gr, HCDT v, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, const char *opt); void mgl_tricont_xycv(HMGL gr, HCDT v, HCDT nums, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt); void mgl_tricont_xyzc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, const char *opt); void mgl_tricont_xyc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt); - + void mgl_dots(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt); void mgl_dots_a(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt); - + void mgl_crust(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt); - -void mgl_dens_x(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_dens_y(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_dens_z(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_cont_x(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_cont_y(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_cont_z(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); +void mgl_dens_x(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_dens_y(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_dens_z(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); + +void mgl_cont_x(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_cont_y(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_cont_z(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); -void mgl_cont_x_val(HMGL graph, HCDT v, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_cont_y_val(HMGL graph, HCDT v, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_cont_z_val(HMGL graph, HCDT v, HCDT a, const char *stl, float sVal, const char *opt); +void mgl_cont_x_val(HMGL graph, HCDT v, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_cont_y_val(HMGL graph, HCDT v, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_cont_z_val(HMGL graph, HCDT v, HCDT a, const char *stl, mreal sVal, const char *opt); -void mgl_contf_x(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_contf_y(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_contf_z(HMGL graph, HCDT a, const char *stl, float sVal, const char *opt); +void mgl_contf_x(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_contf_y(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_contf_z(HMGL graph, HCDT a, const char *stl, mreal sVal, const char *opt); + +void mgl_contf_x_val(HMGL graph, HCDT v, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_contf_y_val(HMGL graph, HCDT v, HCDT a, const char *stl, mreal sVal, const char *opt); +void mgl_contf_z_val(HMGL graph, HCDT v, HCDT a, const char *stl, mreal sVal, const char *opt); -void mgl_contf_x_val(HMGL graph, HCDT v, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_contf_y_val(HMGL graph, HCDT v, HCDT a, const char *stl, float sVal, const char *opt); -void mgl_contf_z_val(HMGL graph, HCDT v, HCDT a, const char *stl, float sVal, const char *opt); - /*****************************************************************************/ void mgl_triplot_xyzc_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int,int); @@ -71,37 +71,37 @@ void mgl_triplot_xy_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, void mgl_quadplot_xyzc_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int,int); void mgl_quadplot_xyz_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *sch, const char *opt,int,int); void mgl_quadplot_xy_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, const char *sch, const char *opt,int,int); - + void mgl_tricont_xyzcv_(uintptr_t *gr, uintptr_t *v, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int,int); void mgl_tricont_xycv_(uintptr_t *gr, uintptr_t *v, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *sch, const char *opt,int,int); void mgl_tricont_xyzc_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int, int); void mgl_tricont_xyc_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *sch, const char *opt,int, int); - + void mgl_dots_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *sch, const char *opt,int,int); void mgl_dots_a_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, const char *opt,int,int); void mgl_dots_tr_(uintptr_t *gr, uintptr_t *tr, const char *sch, const char *opt,int,int); void mgl_crust_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *sch, const char *opt,int,int); void mgl_crust_tr_(uintptr_t *gr, uintptr_t *tr, const char *sch, const char *opt,int,int); - -void mgl_dens_x_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_dens_y_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_dens_z_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_cont_x_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_cont_y_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_cont_z_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_cont_x_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_cont_y_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_cont_z_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_contf_x_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_contf_y_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_contf_z_(uintptr_t *graph, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_contf_x_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_contf_y_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); -void mgl_contf_z_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, float *sVal, const char *opt,int,int); - + +void mgl_dens_x_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_dens_y_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_dens_z_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_cont_x_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_cont_y_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_cont_z_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_cont_x_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_cont_y_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_cont_z_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_contf_x_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_contf_y_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_contf_z_(uintptr_t *graph, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_contf_x_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_contf_y_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); +void mgl_contf_z_val_(uintptr_t *graph, uintptr_t *v, uintptr_t *a, const char *stl, mreal *sVal, const char *opt,int,int); + /*****************************************************************************/ #ifdef __cplusplus } -#endif +#endif /*****************************************************************************/ -#endif +#endif diff --git a/include/mgl2/parser.h b/include/mgl2/parser.h index efcb7c0..9e47330 100644 --- a/include/mgl2/parser.h +++ b/include/mgl2/parser.h @@ -84,10 +84,11 @@ struct mglFunc { long pos; int narg; - std::wstring func; - mglFunc *next; - mglFunc(long p, const wchar_t *f, mglFunc *prev=0); - ~mglFunc() { if(next) delete next; }; +// std::wstring func; + wchar_t func[64]; + mglFunc(long p, const wchar_t *f); + mglFunc(const mglFunc &f); + mglFunc() { pos=narg=-1; *func=0; } }; //----------------------------------------------------------------------------- /// Structure for stack of functions and its arguments. @@ -106,10 +107,10 @@ class mglParser friend void mgl_export(wchar_t *out, const wchar_t *in, int type); public: mglVar *DataList; ///< List with data and its names - mglNum *NumList; ///< List with numbers and its names + mglNum *NumList; ///< List with numbers and its names bool AllowSetSize; ///< Allow using setsize command 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'!!! + mglCommand *Cmd; ///< Table of MGL commands (can be changed by user). It MUST be sorted by 'name'!!! wchar_t *op1, *op2; ///< Buffer for options (are used if out!=NULL) long InUse; ///< Smart pointer (number of users) @@ -181,23 +182,23 @@ public: /// Delete variable by its name void DeleteVar(const wchar_t *name); private: - long parlen; ///< Length of parameter strings + long parlen; ///< Length of parameter strings wchar_t *par[40]; ///< Parameter for substituting instead of $1, ..., $9 wchar_t *out; ///< Buffer for writing C++ code (if not NULL) wchar_t leg[128]; ///< Buffer for legend - bool Once; ///< Flag for command which should be executed only once - bool Skip; ///< Flag that commands should be skiped (inside 'once' block) + 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 - mglFunc *func; ///< function names and position - mglFnStack *fn_stack; ///< function calls stack - int fn_pos; ///< position in function stack - int fn_num; ///< size of 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 if_pos; ///< position in if_stack + std::vector func; ///< function names and position + mglFnStack *fn_stack; ///< function calls stack + int fn_pos; ///< position in function stack + int fn_num; ///< size of 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') + int for_addr; ///< Flag for saving address in variable (for_addr-1) + bool for_br; ///< Break is switched on (skip all comands until 'next') /// Parse command int Exec(mglGraph *gr, const wchar_t *com, long n, mglArg *a, const wchar_t *var, const wchar_t *opt); diff --git a/include/mgl2/plot.h b/include/mgl2/plot.h index 593b082..62e00f9 100644 --- a/include/mgl2/plot.h +++ b/include/mgl2/plot.h @@ -92,9 +92,9 @@ void mgl_mark_y(HMGL graph, HCDT y, HCDT r, const char *pen, const char *opt); void mgl_tube_xyzr(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT r, const char *pen, const char *opt); void mgl_tube_xyr(HMGL graph, HCDT x, HCDT y, HCDT r, const char *pen, const char *opt); void mgl_tube_r(HMGL graph, HCDT y, HCDT r, const char *pen, const char *opt); -void mgl_tube_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, float r, const char *pen, const char *opt); -void mgl_tube_xy(HMGL graph, HCDT x, HCDT y, float r, const char *penl, const char *opt); -void mgl_tube(HMGL graph, HCDT y, float r, const char *pen, const char *opt); +void mgl_tube_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, mreal r, const char *pen, const char *opt); +void mgl_tube_xy(HMGL graph, HCDT x, HCDT y, mreal r, const char *penl, const char *opt); +void mgl_tube(HMGL graph, HCDT y, mreal r, const char *pen, const char *opt); /*****************************************************************************/ void mgl_candle_xyv(HMGL gr, HCDT x, HCDT v1, HCDT v2, HCDT y1, HCDT y2, const char *pen, const char *opt); void mgl_candle_yv(HMGL gr, HCDT v1, HCDT v2, HCDT y1, HCDT y2, const char *pen, const char *opt); @@ -129,9 +129,9 @@ void mgl_mark_y_(uintptr_t *graph, uintptr_t *y, uintptr_t *r, const char *pen, void mgl_tube_xyzr_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *r, const char *pen, const char *opt,int,int); void mgl_tube_xyr_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *r, const char *pen, const char *opt,int,int); void mgl_tube_r_(uintptr_t *graph, uintptr_t *y, uintptr_t *r, const char *pen, const char *opt,int,int); -void mgl_tube_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, float *r, const char *pen, const char *opt,int,int); -void mgl_tube_xy_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, float *r, const char *pen, const char *opt,int,int); -void mgl_tube_(uintptr_t *graph, uintptr_t *y, float *r, const char *pen, const char *opt,int,int); +void mgl_tube_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, mreal *r, const char *pen, const char *opt,int,int); +void mgl_tube_xy_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, mreal *r, const char *pen, const char *opt,int,int); +void mgl_tube_(uintptr_t *graph, uintptr_t *y, mreal *r, const char *pen, const char *opt,int,int); void mgl_candle_xyv_(uintptr_t *gr, uintptr_t *x, uintptr_t *v1, uintptr_t *v2, uintptr_t *y1, uintptr_t *y2, const char *pen, const char *opt,int,int); void mgl_candle_yv_(uintptr_t *gr, uintptr_t *v1, uintptr_t *v2, uintptr_t *y1, uintptr_t *y2, const char *pen, const char *opt,int,int); void mgl_candle_(uintptr_t *gr, uintptr_t *y, uintptr_t *y1, uintptr_t *y2, const char *pen, const char *opt,int,int); diff --git a/include/mgl2/prim.h b/include/mgl2/prim.h index 848d28f..0480481 100644 --- a/include/mgl2/prim.h +++ b/include/mgl2/prim.h @@ -25,24 +25,24 @@ extern "C" { #endif /*****************************************************************************/ -void mgl_mark(HMGL gr, float x,float y,float z,const char *mark); -void mgl_ball(HMGL gr, float x,float y,float z); +void mgl_mark(HMGL gr, mreal x,mreal y,mreal z,const char *mark); +void mgl_ball(HMGL gr, mreal x,mreal y,mreal z); /*****************************************************************************/ -void mgl_line(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, const char *pen,int n); -void mgl_curve(HMGL gr, float x1, float y1, float z1, float dx1, float dy1, float dz1, float x2, float y2, float z2, float dx2, float dy2, float dz2, const char *pen,int n); +void mgl_line(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, const char *pen,int n); +void mgl_curve(HMGL gr, mreal x1, mreal y1, mreal z1, mreal dx1, mreal dy1, mreal dz1, mreal x2, mreal y2, mreal z2, mreal dx2, mreal dy2, mreal dz2, const char *pen,int n); /*****************************************************************************/ -void mgl_error_box(HMGL gr, float x, float y, float z, float ex, float ey, float ez, const char *pen); +void mgl_error_box(HMGL gr, mreal x, mreal y, mreal z, mreal ex, mreal ey, mreal ez, const char *pen); /*****************************************************************************/ -void mgl_face(HMGL gr, float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, const char *stl); -void mgl_facex(HMGL gr, float x0, float y0, float z0, float wy, float wz, const char *stl, float dx, float dy); -void mgl_facey(HMGL gr, float x0, float y0, float z0, float wx, float wz, const char *stl, float dx, float dy); -void mgl_facez(HMGL gr, float x0, float y0, float z0, float wx, float wy, const char *stl, float dx, float dy); +void mgl_face(HMGL gr, mreal x0, mreal y0, mreal z0, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal x3, mreal y3, mreal z3, const char *stl); +void mgl_facex(HMGL gr, mreal x0, mreal y0, mreal z0, mreal wy, mreal wz, const char *stl, mreal dx, mreal dy); +void mgl_facey(HMGL gr, mreal x0, mreal y0, mreal z0, mreal wx, mreal wz, const char *stl, mreal dx, mreal dy); +void mgl_facez(HMGL gr, mreal x0, mreal y0, mreal z0, mreal wx, mreal wy, const char *stl, mreal dx, mreal dy); /*****************************************************************************/ -void mgl_sphere(HMGL gr, float x, float y, float z, float r, const char *stl); -void mgl_drop(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, float r, const char *stl, float shift, float ap); -void mgl_cone(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2, const char *stl); -void mgl_ellipse(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, float r, const char *stl); -void mgl_rhomb(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, float r, const char *stl); +void mgl_sphere(HMGL gr, mreal x, mreal y, mreal z, mreal r, const char *stl); +void mgl_drop(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal r, const char *stl, mreal shift, mreal ap); +void mgl_cone(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal r1, mreal r2, const char *stl); +void mgl_ellipse(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal r, const char *stl); +void mgl_rhomb(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal r, const char *stl); /*****************************************************************************/ void mgl_cones_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, const char *pen, const char *opt); void mgl_cones_xz(HMGL graph, HCDT x, HCDT z, const char *pen, const char *opt); @@ -51,11 +51,11 @@ void mgl_cones(HMGL graph, HCDT z, const char *pen, const char *opt); void mgl_dew_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt); void mgl_dew_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, const char *optl); /*****************************************************************************/ -void mgl_puts(HMGL graph, float x, float y, float z,const char *text, const char *font, float size); -void mgl_putsw(HMGL graph, float x, float y, float z,const wchar_t *text, const char *font, float size); +void mgl_puts(HMGL graph, mreal x, mreal y, mreal z,const char *text, const char *font, mreal size); +void mgl_putsw(HMGL graph, mreal x, mreal y, mreal z,const wchar_t *text, const char *font, mreal size); /*****************************************************************************/ -void mgl_puts_dir(HMGL graph, float x, float y, float z, float dx, float dy, float dz, const char *text, const char *font, float size); -void mgl_putsw_dir(HMGL graph, float x, float y, float z, float dx, float dy, float dz, const wchar_t *text, const char *font, float size); +void mgl_puts_dir(HMGL graph, mreal x, mreal y, mreal z, mreal dx, mreal dy, mreal dz, const char *text, const char *font, mreal size); +void mgl_putsw_dir(HMGL graph, mreal x, mreal y, mreal z, mreal dx, mreal dy, mreal dz, const wchar_t *text, const char *font, mreal size); /*****************************************************************************/ void mgl_textmark_xyzr(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT r, const char *text, const char *fnt, const char *opt); void mgl_textmark_xyr(HMGL graph, HCDT x, HCDT y, HCDT r, const char *text, const char *fnt, const char *opt); @@ -66,8 +66,6 @@ void mgl_textmarkw_xyr(HMGL graph, HCDT x, HCDT y, HCDT r, const wchar_t *text, void mgl_textmarkw_yr(HMGL graph, HCDT y, HCDT r, const wchar_t *text, const char *fnt, const char *opt); void mgl_textmarkw(HMGL graph, HCDT y, const wchar_t *text, const char *fnt, const char *opt); /*****************************************************************************/ -void mgl_puts_fit(HMGL gr, float x, float y, float z, const char *prefix, const char *font, float size); -/*****************************************************************************/ void mgl_label_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, const char *text, const char *fnt, const char *opt); void mgl_labelw_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, const wchar_t *text, const char *fnt, const char *opt); void mgl_label_xy(HMGL graph, HCDT x, HCDT y, const char *text, const char *fnt, const char *opt); @@ -76,39 +74,37 @@ void mgl_label_y(HMGL graph, HCDT y, const char *text, const char *fnt, const ch void mgl_labelw_y(HMGL graph, HCDT y, const wchar_t *text, const char *fnt, const char *opt); /*****************************************************************************/ /*****************************************************************************/ -void mgl_mark_(uintptr_t *gr, float *x,float *y,float *z,const char *mark,int); -void mgl_ball_(uintptr_t *gr, float *x,float *y,float *z); +void mgl_mark_(uintptr_t *gr, mreal *x,mreal *y,mreal *z,const char *mark,int); +void mgl_ball_(uintptr_t *gr, mreal *x,mreal *y,mreal *z); /*****************************************************************************/ -void mgl_line_(uintptr_t *gr, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, const char *pen,int *n,int); -void mgl_curve_(uintptr_t* gr, float *x1, float *y1, float *z1, float *dx1, float *dy1, float *dz1, float *x2, float *y2, float *z2, float *dx2, float *dy2, float *dz2, const char *pen,int *n, int l); +void mgl_line_(uintptr_t *gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, const char *pen,int *n,int); +void mgl_curve_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *dx1, mreal *dy1, mreal *dz1, mreal *x2, mreal *y2, mreal *z2, mreal *dx2, mreal *dy2, mreal *dz2, const char *pen,int *n, int l); /*****************************************************************************/ -void mgl_error_box_(uintptr_t* gr, float *x, float *y, float *z, float *ex, float *ey, float *ez, const char *pen, int); +void mgl_error_box_(uintptr_t* gr, mreal *x, mreal *y, mreal *z, mreal *ex, mreal *ey, mreal *ez, const char *pen, int); /*****************************************************************************/ -void mgl_face_(uintptr_t* gr, float *x0, float *y0, float *z0, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, float *x3, float *y3, float *z3, const char *stl, int); -void mgl_facex_(uintptr_t* gr, float *x0, float *y0, float *z0, float *wy, float *wz, const char *stl, float *dx, float *dy, int l); -void mgl_facey_(uintptr_t* gr, float *x0, float *y0, float *z0, float *wx, float *wz, const char *stl, float *dx, float *dy, int l); -void mgl_facez_(uintptr_t* gr, float *x0, float *y0, float *z0, float *wx, float *wy, const char *stl, float *dx, float *dy, int l); +void mgl_face_(uintptr_t* gr, mreal *x0, mreal *y0, mreal *z0, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, mreal *x3, mreal *y3, mreal *z3, const char *stl, int); +void mgl_facex_(uintptr_t* gr, mreal *x0, mreal *y0, mreal *z0, mreal *wy, mreal *wz, const char *stl, mreal *dx, mreal *dy, int l); +void mgl_facey_(uintptr_t* gr, mreal *x0, mreal *y0, mreal *z0, mreal *wx, mreal *wz, const char *stl, mreal *dx, mreal *dy, int l); +void mgl_facez_(uintptr_t* gr, mreal *x0, mreal *y0, mreal *z0, mreal *wx, mreal *wy, const char *stl, mreal *dx, mreal *dy, int l); /*****************************************************************************/ -void mgl_sphere_(uintptr_t* gr, float *x, float *y, float *z, float *r, const char *stl, int); -void mgl_drop_(uintptr_t* gr, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, float *r, const char *stl, float *shift, float *ap, int); -void mgl_cone_(uintptr_t* gr, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, float *r1, float *r2, const char *stl, int); -void mgl_ellipse_(uintptr_t* gr, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, float *r, const char *stl, int); -void mgl_rhomb_(uintptr_t* gr, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, float *r, const char *stl, int); +void mgl_sphere_(uintptr_t* gr, mreal *x, mreal *y, mreal *z, mreal *r, const char *stl, int); +void mgl_drop_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, mreal *r, const char *stl, mreal *shift, mreal *ap, int); +void mgl_cone_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, mreal *r1, mreal *r2, const char *stl, int); +void mgl_ellipse_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, mreal *r, const char *stl, int); +void mgl_rhomb_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, mreal *r, const char *stl, int); /*****************************************************************************/ void mgl_cones_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *pen, const char *opt,int,int); void mgl_coners_xz_(uintptr_t *graph, uintptr_t *x, uintptr_t *z, const char *pen, const char *opt,int,int); void mgl_cones_(uintptr_t *graph, uintptr_t *z, const char *pen, const char *opt,int,int); /*****************************************************************************/ -void mgl_puts_(uintptr_t *graph, float *x, float *y, float *z,const char *text, const char *font, float *size, int, int); -void mgl_puts_dir_(uintptr_t *graph, float *x, float *y, float *z, float *dx, float *dy, float *dz, const char *text, const char *font, float *size, int, int); +void mgl_puts_(uintptr_t *graph, mreal *x, mreal *y, mreal *z,const char *text, const char *font, mreal *size, int, int); +void 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_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); void mgl_textmark_xyr_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *r, const char *text, const char *fnt, const char *opt,int,int,int); void mgl_textmark_yr_(uintptr_t *graph, uintptr_t *y, uintptr_t *r, const char *text, const char *fnt, const char *opt,int,int,int); void mgl_textmark_(uintptr_t *graph, uintptr_t *y, const char *text, const char *fnt, const char *opt,int,int,int); /*****************************************************************************/ -void mgl_puts_fit_(uintptr_t* gr, float *x, float *y, float *z, const char *prefix, const char *font, float *size, int l, int n); -/*****************************************************************************/ void mgl_label_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *text, const char *fnt, const char *opt,int,int,int); void mgl_label_xy_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, const char *text, const char *fnt, const char *opt,int,int,int); void mgl_label_y_(uintptr_t *graph, uintptr_t *y, const char *text, const char *fnt, const char *opt,int,int,int); diff --git a/include/mgl2/qt.h b/include/mgl2/qt.h index 7fbcae6..59dc72b 100644 --- a/include/mgl2/qt.h +++ b/include/mgl2/qt.h @@ -59,7 +59,7 @@ public: { draw = dr; } inline void setDraw(int (*draw)(mglGraph *gr)) { setDraw(mgl_draw_graph,(void*)draw); } - inline void zoomRegion(float xx1,float xx2,float yy1, float yy2) + inline void zoomRegion(mreal xx1,mreal xx2,mreal yy1, mreal yy2) { x1=xx1; y1=yy1; x2=xx2; y2=yy2; } int getPer() {return int(per);}; ///< Get perspective value @@ -129,7 +129,7 @@ signals: void lightChanged(bool); ///< Lighting changed (by toolbar) void zoomChanged(bool); ///< Zooming changed (by toolbar) void rotateChanged(bool); ///< Rotation changed (by toolbar) - void mouseClick(float,float,float); ///< Position of mouse click + void mouseClick(mreal,mreal,mreal); ///< Position of mouse click void frameChanged(int); ///< Need another frame to show void showWarn(QString); ///< Show warnings void posChanged(QString message); ///< user click to show mouse position @@ -157,7 +157,7 @@ protected: bool zoom; ///< Mouse zoom state bool grid; ///< Grid drawing state bool rotate; ///< Mouse rotation state - float x1,x2,y1,y2; ///< Zoom in region + mreal x1,x2,y1,y2; ///< Zoom in region bool showMessage; ///< Flag for showing messages (enabled by each execute()) QMenu *popup; ///< Pointer to pop-up menu QTimer *timer; ///< Timer for animation diff --git a/include/mgl2/type.h b/include/mgl2/type.h index d598b0f..f296432 100644 --- a/include/mgl2/type.h +++ b/include/mgl2/type.h @@ -19,8 +19,7 @@ ***************************************************************************/ #ifndef _MGL_TYPE_H_ #define _MGL_TYPE_H_ -#include -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(__BORLANDC__) #include #endif #include "mgl2/define.h" @@ -28,22 +27,27 @@ const mreal Pi = M_PI; const mreal NaN = NAN; //----------------------------------------------------------------------------- +#define MGL_SET_XYZ(p,xx,yy,zz) {p.x=(xx);p.y=(yy);p.z=(zz);} +#define MGL_SET_XY(p,xx,yy) {p.x=(xx);p.y=(yy);p.z=0;} +#define MGL_SET_RGBA(p,rr,gg,bb,aa) {p.r=(rr);p.g=(gg);p.b=(bb);p.a=(aa);} +#define MGL_SET_RGB(p,rr,gg,bb) {p.r=(rr);p.g=(gg);p.b=(bb);} +//----------------------------------------------------------------------------- /// Class for incapsulating point in space struct mglPoint { - float x,y,z,c; - mglPoint(float X=0,float Y=0,float Z=0,float C=0){x=X;y=Y;z=Z;c=C;} + 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;} inline bool IsNAN() { return (x!=x || y!=y || z!=z || c!=c); } - inline float val(int i) { return (i<2 ? (i==0 ? x:y) : (i==2 ? z:c)); } - inline float norm() { return sqrt(x*x+y*y+z*z); } - inline void Normalize() { float v=norm(); x/=v; y/=v; z/=v; } + 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 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+=(float a) { x+=a; y+=a; z+=a; } - inline void operator-=(float a) { x-=a; y-=a; z-=a; } - inline void operator*=(float a) { x*=a; y*=a; z*=a; } - inline void operator/=(float a) { x/=a; y/=a; z/=a; } + inline void operator+=(mreal a) { x+=a; y+=a; z+=a; } + inline void operator-=(mreal a) { x-=a; y-=a; z-=a; } + inline void operator*=(mreal a) { x*=a; y*=a; z*=a; } + inline void operator/=(mreal a) { x/=a; y/=a; z/=a; } }; #ifndef SWIG inline mglPoint operator+(const mglPoint &a, const mglPoint &b) @@ -52,13 +56,13 @@ inline mglPoint operator-(const mglPoint &a, const mglPoint &b) { return mglPoint(a.x-b.x, a.y-b.y, a.z-b.z, a.c-b.c); } inline mglPoint operator-(const mglPoint &a) { return mglPoint(-a.x, -a.y, -a.z, -a.c); } -inline mglPoint operator*(float b, const mglPoint &a) +inline mglPoint operator*(mreal b, const mglPoint &a) { return mglPoint(a.x*b, a.y*b, a.z*b); } -inline mglPoint operator*(const mglPoint &a, float b) +inline mglPoint operator*(const mglPoint &a, mreal b) { return mglPoint(a.x*b, a.y*b, a.z*b); } -inline mglPoint operator/(const mglPoint &a, float b) +inline mglPoint operator/(const mglPoint &a, mreal b) { return mglPoint(a.x/b, a.y/b, a.z/b); } -inline float operator*(const mglPoint &a, const mglPoint &b) +inline mreal operator*(const mglPoint &a, const mglPoint &b) { return a.x*b.x+a.y*b.y+a.z*b.z; } inline mglPoint operator/(const mglPoint &a, const mglPoint &b) { return mglPoint(a.x*b.x, a.y*b.y, a.z*b.z); } @@ -69,12 +73,16 @@ inline mglPoint operator|(const mglPoint &a, const mglPoint &b) 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) -{ float f=hypot(a.x,a.y); return f==0?mglPoint(0,1,0):mglPoint(-a.y/f, a.x/f, 0); } +{ mreal f=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) { return !memcmp(&a, &b, sizeof(mglPoint)); } inline bool operator!=(const mglPoint &a, const mglPoint &b) { return memcmp(&a, &b, sizeof(mglPoint)); } -inline float mgl_norm(const mglPoint &p) +inline bool operator<(const mglPoint &a, const mglPoint &b) +{ return a.x<=b.x && a.y<=b.y && a.z<=b.z; } +inline bool operator>(const mglPoint &a, const mglPoint &b) +{ return a.x>=b.x && a.y>=b.y && a.z>=b.z; } +inline mreal mgl_norm(const mglPoint &p) { return sqrt(p.x*p.x+p.y*p.y+p.z*p.z); } #endif //----------------------------------------------------------------------------- diff --git a/include/mgl2/vect.h b/include/mgl2/vect.h index 1821e08..566b4b0 100644 --- a/include/mgl2/vect.h +++ b/include/mgl2/vect.h @@ -2,87 +2,87 @@ * vect.h is part of Math Graphic Library * Copyright (C) 2007 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. * - ***************************************************************************/ + * 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_VECT_H_ -#define _MGL_VECT_H_ +#define _MGL_VECT_H_ #include "mgl2/base.h" /*****************************************************************************/ -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif /*****************************************************************************/ void mgl_traj_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt); void mgl_traj_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); - + void mgl_vect_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt); void mgl_vect_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, const char *opt); void mgl_vect_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); void mgl_vect_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); - + void mgl_flow_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt); void mgl_flow_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, const char *opt); void mgl_flow_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); void mgl_flow_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); -void mgl_flowp_xy(HMGL gr, float x0, float y0, float z0, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt); -void mgl_flowp_2d(HMGL gr, float x0, float y0, float z0, HCDT ax, HCDT ay, const char *sch, const char *opt); -void mgl_flowp_xyz(HMGL gr, float x0, float y0, float z0, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); -void mgl_flowp_3d(HMGL gr, float x0, float y0, float z0, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); +void mgl_flowp_xy(HMGL gr, mreal x0, mreal y0, mreal z0, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt); +void mgl_flowp_2d(HMGL gr, mreal x0, mreal y0, mreal z0, HCDT ax, HCDT ay, const char *sch, const char *opt); +void mgl_flowp_xyz(HMGL gr, mreal x0, mreal y0, mreal z0, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); +void mgl_flowp_3d(HMGL gr, mreal x0, mreal y0, mreal z0, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt); + +void mgl_pipe_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, mreal r0, const char *opt); +void mgl_pipe_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, mreal r0, const char *opt); +void mgl_pipe_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, mreal r0, const char *opt); +void mgl_pipe_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, mreal r0, const char *opt); -void mgl_pipe_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, float r0, const char *opt); -void mgl_pipe_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, float r0, const char *opt); -void mgl_pipe_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, float r0, const char *opt); -void mgl_pipe_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, float r0, const char *opt); - void mgl_grad_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ph, const char *sch, const char *opt); void mgl_grad_xy(HMGL gr, HCDT x, HCDT y, HCDT ph, const char *sch, const char *opt); void mgl_grad(HMGL gr, HCDT ph, const char *sch, const char *opt); - + /*****************************************************************************/ void mgl_traj_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int,int); void mgl_traj_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int,int); - + void mgl_vect_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int,int); void mgl_vect_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int,int); void mgl_vect_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int,int); void mgl_vect_3d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int,int); - + void mgl_flow_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int,int); void mgl_flow_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int,int); void mgl_flow_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int,int); void mgl_flow_3d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int,int); -void mgl_flowp_xy_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int, int); -void mgl_flowp_2d_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int, int); -void mgl_flowp_xyz_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int, int); -void mgl_flowp_3d_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int,int); +void mgl_flowp_xy_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int, int); +void mgl_flowp_2d_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int, int); +void mgl_flowp_xyz_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int, int); +void mgl_flowp_3d_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int,int); + +void mgl_pipe_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, mreal *r0, const char *opt,int,int); +void mgl_pipe_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, mreal *r0, const char *opt,int,int); +void mgl_pipe_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, mreal *r0, const char *opt,int,int); +void mgl_pipe_3d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, mreal *r0, const char *opt,int,int); -void mgl_pipe_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, float *r0, const char *opt,int,int); -void mgl_pipe_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, float *r0, const char *opt,int,int); -void mgl_pipe_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, float *r0, const char *opt,int,int); -void mgl_pipe_3d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, float *r0, const char *opt,int,int); - void mgl_grad_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ph, const char *sch, const char *opt,int, int); void mgl_grad_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ph, const char *sch, const char *opt,int,int); void mgl_grad_(uintptr_t *gr, uintptr_t *ph, const char *sch, const char *opt,int,int); - + /*****************************************************************************/ #ifdef __cplusplus } -#endif +#endif /*****************************************************************************/ -#endif +#endif diff --git a/include/mgl2/volume.h b/include/mgl2/volume.h index 78e7fa4..9895446 100644 --- a/include/mgl2/volume.h +++ b/include/mgl2/volume.h @@ -2,78 +2,78 @@ * volume.h is part of Math Graphic Library * Copyright (C) 2007 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. * - ***************************************************************************/ + * 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_VOL_H_ -#define _MGL_VOL_H_ +#define _MGL_VOL_H_ #include "mgl2/base.h" /*****************************************************************************/ -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif /*****************************************************************************/ -void mgl_surf3_xyz_val(HMGL graph, float Val, HCDT x, HCDT y, HCDT z, HCDT a, const char *stl, const char *opt); -void mgl_surf3_val(HMGL graph, float Val, HCDT a, const char *stl, const char *opt); +void mgl_surf3_xyz_val(HMGL graph, mreal Val, HCDT x, HCDT y, HCDT z, HCDT a, const char *stl, const char *opt); +void mgl_surf3_val(HMGL graph, mreal Val, HCDT a, const char *stl, const char *opt); void mgl_surf3_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT a, const char *stl, const char *opt); void mgl_surf3(HMGL graph, HCDT a, const char *stl, const char *opt); - -void mgl_surf3a_xyz_val(HMGL graph, float Val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *stl, const char *opt); -void mgl_surf3a_val(HMGL graph, float Val, HCDT a, HCDT b, const char *stl, const char *opt); + +void mgl_surf3a_xyz_val(HMGL graph, mreal Val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *stl, const char *opt); +void mgl_surf3a_val(HMGL graph, mreal Val, HCDT a, HCDT b, const char *stl, const char *opt); void mgl_surf3a_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *stl, const char *opt); void mgl_surf3a(HMGL graph, HCDT a, HCDT b, const char *stl, const char *opt); - -void mgl_surf3c_xyz_val(HMGL graph, float Val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *stl, const char *opt); -void mgl_surf3c_val(HMGL graph, float Val, HCDT a, HCDT b, const char *stl, const char *opt); + +void mgl_surf3c_xyz_val(HMGL graph, mreal Val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *stl, const char *opt); +void mgl_surf3c_val(HMGL graph, mreal Val, HCDT a, HCDT b, const char *stl, const char *opt); void mgl_surf3c_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *stl, const char *opt); void mgl_surf3c(HMGL graph, HCDT a, HCDT b, const char *stl, const char *opt); - -// NOTE: now style '.' draws dots instead of faces + +// NOTE: now style '.' draws dots instead of faces void mgl_cloud_xyz(HMGL graph, HCDT x, HCDT y, HCDT z, HCDT a, const char *stl, const char *opt); void mgl_cloud(HMGL graph, HCDT a, const char *stl, const char *opt); - -void mgl_beam_val(HMGL graph, float Val, HCDT tr, HCDT g1, HCDT g2, HCDT a, float r, const char *stl, int norm); -void mgl_beam(HMGL graph, HCDT tr, HCDT g1, HCDT g2, HCDT a, float r, const char *stl, int norm, int num); - + +void mgl_beam_val(HMGL graph, mreal Val, HCDT tr, HCDT g1, HCDT g2, HCDT a, mreal r, const char *stl, int norm); +void mgl_beam(HMGL graph, HCDT tr, HCDT g1, HCDT g2, HCDT a, mreal r, const char *stl, int norm, int num); + /*****************************************************************************/ -void mgl_surf3_xyz_val_(uintptr_t *graph, float *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *stl, const char *opt,int,int); -void mgl_surf3_val_(uintptr_t *graph, float *Val, uintptr_t *a, const char *stl, const char *opt,int,int); +void mgl_surf3_xyz_val_(uintptr_t *graph, mreal *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *stl, const char *opt,int,int); +void mgl_surf3_val_(uintptr_t *graph, mreal *Val, uintptr_t *a, const char *stl, const char *opt,int,int); void mgl_surf3_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *stl, const char *opt,int,int); void mgl_surf3_(uintptr_t *graph, uintptr_t *a, const char *stl, const char *opt,int,int); - -void mgl_surf3a_xyz_val_(uintptr_t *graph, float *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); -void mgl_surf3a_val_(uintptr_t *graph, float *Val, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); + +void mgl_surf3a_xyz_val_(uintptr_t *graph, mreal *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); +void mgl_surf3a_val_(uintptr_t *graph, mreal *Val, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); void mgl_surf3a_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); void mgl_surf3a_(uintptr_t *graph, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); - -void mgl_surf3c_xyz_val_(uintptr_t *graph, float *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); -void mgl_surf3c_val_(uintptr_t *graph, float *Val, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); + +void mgl_surf3c_xyz_val_(uintptr_t *graph, mreal *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); +void mgl_surf3c_val_(uintptr_t *graph, mreal *Val, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); void mgl_surf3c_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); void mgl_surf3c_(uintptr_t *graph, uintptr_t *a, uintptr_t *b, const char *stl, const char *opt,int,int); - + void mgl_cloudp_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *stl, const char *opt,int,int); void mgl_cloudp_(uintptr_t *graph, uintptr_t *a, const char *stl, const char *opt,int,int); void mgl_cloud_xyz_(uintptr_t *graph, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *stl, const char *opt,int,int); void mgl_cloud_(uintptr_t *graph, uintptr_t *a, const char *stl, const char *opt,int,int); - -void mgl_beam_val_(uintptr_t *gr, float *val, uintptr_t *tr, uintptr_t *g1, uintptr_t *g2, uintptr_t *a, float *r, const char *sch, int *norm,int l); -void mgl_beam_(uintptr_t *gr, uintptr_t *tr, uintptr_t *g1, uintptr_t *g2, uintptr_t *a, float *r, const char *sch, int *norm, int *num,int l); - + +void mgl_beam_val_(uintptr_t *gr, mreal *val, uintptr_t *tr, uintptr_t *g1, uintptr_t *g2, uintptr_t *a, mreal *r, const char *sch, int *norm,int l); +void mgl_beam_(uintptr_t *gr, uintptr_t *tr, uintptr_t *g1, uintptr_t *g2, uintptr_t *a, mreal *r, const char *sch, int *norm, int *num,int l); + /*****************************************************************************/ #ifdef __cplusplus } -#endif +#endif /*****************************************************************************/ -#endif +#endif diff --git a/include/mgl2/window.h b/include/mgl2/window.h index 504f179..21e44cc 100644 --- a/include/mgl2/window.h +++ b/include/mgl2/window.h @@ -39,22 +39,25 @@ struct mglDraw { mgl_draw_thr(this); } #endif }; -typedef int (*draw_func)(mglGraph *gr); -int mgl_draw_graph(mglBase *gr, void *p); +//----------------------------------------------------------------------------- +extern "C" { +int mgl_draw_graph(HMGL gr, void *p); // NOTE: mgl_draw_class() and mgl_draw_load() use mglWindow* only. Don't use it with inherited classes -int mgl_draw_class(mglBase *gr, void *p); +int mgl_draw_class(HMGL gr, void *p); void mgl_click_class(void *p); void mgl_reload_class(void *p); +} //----------------------------------------------------------------------------- #if MGL_HAVE_QT #define MGL_WND_KIND 1 #else #define MGL_WND_KIND 0 #endif +//----------------------------------------------------------------------------- /// Wrapper class for windows displaying graphics class mglWindow : public mglGraph { -friend int mgl_draw_class(mglBase *gr, void *p); +friend int mgl_draw_class(HMGL gr, void *p); friend void mgl_click_class(void *p); friend void mgl_reload_class(void *p); protected: @@ -62,7 +65,7 @@ protected: int wnd; ///< Type of window public: mglWindow(const char *title="MathGL") : mglGraph(-1) - { wnd=0; dr=0; gr = mgl_create_graph_fltk(0,title,0,0); } + { wnd=0; dr=0; gr = mgl_create_graph_fltk(0,title,0,0); mgl_use_graph(gr,1); } inline int RunThr() ///< Run main loop for event handling in separate thread (for FLTK only) { return wnd==0 ? mgl_fltk_thr():0; } #ifndef SWIG @@ -71,25 +74,28 @@ public: wnd=kind; dr=0; if(wnd==1) gr = mgl_create_graph_qt(draw,title,par,load); else gr = mgl_create_graph_fltk(draw,title,par,load); + mgl_use_graph(gr,1); } mglWindow(int (*draw)(mglGraph *gr), const char *title="MathGL", int kind=MGL_WND_KIND) : mglGraph(-1) { wnd=kind; dr=0; if(wnd==1) gr = mgl_create_graph_qt(mgl_draw_graph,title,(void*)draw,0); else gr = mgl_create_graph_fltk(mgl_draw_graph,title,(void*)draw,0); + mgl_use_graph(gr,1); } mglWindow(mglDraw *draw, const char *title="MathGL", int kind=MGL_WND_KIND) : mglGraph(-1) { wnd=kind; dr=draw; if(wnd==1) gr = mgl_create_graph_qt(mgl_draw_class,title,this,mgl_reload_class); else gr = mgl_create_graph_fltk(mgl_draw_class,title,this,mgl_reload_class); + mgl_use_graph(gr,1); mgl_set_click_func(gr, mgl_click_class); } inline int Run() ///< Run main loop for event handling { return (wnd==1)? mgl_qt_run() : mgl_fltk_run(); } #endif - inline void ToggleAlpha() ///< Switch on/off transparency (do not overwrite user settings) + inline void ToggleAlpha() ///< Switch on/off transparency (do not overwrite user settings) { mgl_wnd_toggle_alpha(gr); } inline void ToggleLight() ///< Switch on/off lighting (do not overwrite user settings) { mgl_wnd_toggle_light(gr); } @@ -114,12 +120,12 @@ public: void SetClickFunc(void (*func)(void *p)) { if(!dr) mgl_set_click_func(gr,func); } - inline void SetDelay(float dt) ///< Delay for animation in seconds + inline void SetDelay(mreal dt) ///< Delay for animation in seconds { mgl_wnd_set_delay(gr, dt); } inline void Setup(bool clf_upd=true, bool showpos=false) { mgl_setup_window(gr, clf_upd, showpos); } inline mglPoint LastMousePos() ///< Last mouse position - { mglPoint p; mgl_get_last_mouse_pos(gr,&p.x,&p.y,&p.z); return p; } + { mreal x,y,z; mgl_get_last_mouse_pos(gr,&x,&y,&z); return mglPoint(x,y,z); } }; //----------------------------------------------------------------------------- #endif diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index d6467f0..cfdc3a7 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -76,19 +76,35 @@ message(STATUS "${oct_prog} ${oct_host} ${oct_api}") ) # -L$ #commented out for compatibilty reason with old cmake # -L$ #commented out for compatibilty reason with old cmake - add_custom_command(OUTPUT ${pkg_name}/inst/${oct_arch}/mathgl.oct - COMMAND ${oct_mk} ${MGL_DEF} + add_custom_command(OUTPUT mgl_octave.o + COMMAND ${oct_mk} -c ${MGL_DEF} -I${oct_inc} -I${BIN_INC} -I${SRC_INC} + -o mgl_octave.o mgl_octave.cpp + DEPENDS ${src_dep} mgl_octave.cpp + IMPLICIT_DEPENDS CXX ${src_imp_dep} + ) + add_custom_command(OUTPUT ${pkg_name}/inst/${oct_arch}/mathgl.oct + COMMAND ${oct_mk} -L${MGL_LINK_DIR} -L${MGL_WND_LINK_DIR} -lmgl-wnd -lmgl - -o ${pkg_name}/inst/${oct_arch}/mathgl.oct mgl_octave.cpp - DEPENDS ${dep_libs} ${src_dep} mgl_octave.cpp - IMPLICIT_DEPENDS CXX ${src_imp_dep} + -o ${pkg_name}/inst/${oct_arch}/mathgl.oct mgl_octave.o + DEPENDS ${dep_libs} mgl_octave.o ) +# add_custom_command(OUTPUT ${pkg_name}/inst/${oct_arch}/mathgl.oct +# COMMAND ${oct_mk} ${MGL_DEF} +# -I${oct_inc} -I${BIN_INC} -I${SRC_INC} +# -L${MGL_LINK_DIR} +# -L${MGL_WND_LINK_DIR} +# -lmgl-wnd -lmgl +# -o ${pkg_name}/inst/${oct_arch}/mathgl.oct mgl_octave.cpp +# DEPENDS ${dep_libs} ${src_dep} mgl_octave.cpp +# ) add_custom_command(OUTPUT mathgl.tar.gz COMMAND ${oct_tar} cpzvf mathgl.tar.gz ${pkg_name} DEPENDS ${pkg_name}/inst/${oct_arch}/mathgl.oct ) add_custom_target(mgl_octave_module ALL DEPENDS mathgl.tar.gz) + install(CODE "execute_process(COMMAND ${oct_exec} ${CMAKE_SOURCE_DIR}/lang/install.m WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/lang )") + endif(MGL_HAVE_OCTAVE) diff --git a/lang/install.m b/lang/install.m new file mode 100644 index 0000000..b95a5ad --- /dev/null +++ b/lang/install.m @@ -0,0 +1 @@ +pkg install mathgl.tar.gz diff --git a/lang/mgl.i.in b/lang/mgl.i.in index bbf1e4f..d675422 100644 --- a/lang/mgl.i.in +++ b/lang/mgl.i.in @@ -58,16 +58,13 @@ typedef float mreal; %rename(__div) operator/; %rename(__eq) operator==; %rename(__ne) operator!=; -//%typemap(in,noblock=1) (double* d, int rows, int cols) (Matrix tmp) { -// if (!$input.is_matrix_type()) { -// error("A must be a matrix"); -// SWIG_fail; -// } -// tmp=$input.matrix_value(); -// $1=tmp.data(); -// $2=tmp.rows(); -// $3=tmp.columns(); -//} +%typemap(in,noblock=1) (double* d, int rows, int cols) (Matrix tmp) { + if (!$input.is_matrix_type()) { error("A must be a matrix"); SWIG_fail; } + tmp=$input.matrix_value(); + $1=tmp.data(); + $2=tmp.rows(); + $3=tmp.columns(); +} #endif #ifdef SWIGPYTHON diff --git a/mgllab/CMakeLists.txt b/mgllab/CMakeLists.txt index 5bba67e..106ff36 100644 --- a/mgllab/CMakeLists.txt +++ b/mgllab/CMakeLists.txt @@ -1,8 +1,8 @@ if(MGL_HAVE_FLTK) include_directories(${FLTK_INCLUDE_DIR}) - set(mgl_lab_src animate.cpp editor.cpp help.cpp mathgl.cpp setup.cpp write.cpp data.cpp grid.cpp main.cpp option.cpp table.cpp ../widgets/fltk.cpp ../widgets/window.cpp) + set(mgl_lab_src animate.cpp editor.cpp help.cpp mathgl.cpp setup.cpp write.cpp data.cpp grid.cpp main.cpp option.cpp table.cpp) add_executable(mgllab ${mgl_lab_src}) - target_link_libraries(mgllab mgl ${FLTK_LIBRARIES}) + target_link_libraries(mgllab mgl mgl-wnd ${FLTK_LIBRARIES}) install( TARGETS mgllab RUNTIME DESTINATION bin ) diff --git a/mgllab/animate.cpp b/mgllab/animate.cpp index 5565a33..0571d5f 100644 --- a/mgllab/animate.cpp +++ b/mgllab/animate.cpp @@ -188,7 +188,7 @@ void AnimateDlg::create_dlg() void AnimateDlg::FillResult(Fl_MGL* e) { e->NArgs = e->ArgCur = 0; - if(e->ArgBuf) delete []e->ArgBuf; e->ArgBuf = 0; + if(e->ArgBuf) delete [](e->ArgBuf); e->ArgBuf = 0; e->AnimDelay = atof(dt->value()); if(rt->value()) { diff --git a/mgllab/data.cpp b/mgllab/data.cpp index 7f6bf3b..461ebb3 100644 --- a/mgllab/data.cpp +++ b/mgllab/data.cpp @@ -190,7 +190,7 @@ struct CmdDlg void cmd_dlg_cb(Fl_Widget *, void *v) // add variables checking { cmd_dlg.OK = true; ((Fl_Window *)v)->hide(); } //----------------------------------------------------------------------------- -void type_cmd_cb(Fl_Widget *w, void *v) +void type_cmd_cb(Fl_Widget *, void *) { int val = cmd_dlg.type->value(); if(val>=0 && val<16) @@ -211,7 +211,7 @@ void type_cmd_cb(Fl_Widget *w, void *v) cmd_dlg.cmd->value(0); } //----------------------------------------------------------------------------- -void desc_cmd_cb(Fl_Widget *w, void *v) +void desc_cmd_cb(Fl_Widget *, void *) { const char *name = cmd_dlg.cmd->mvalue()->text; cmd_dlg.dsc->copy_label(Parse->CmdDesc(name)); @@ -342,7 +342,7 @@ void command_cb(Fl_Widget *, void *v) } } //----------------------------------------------------------------------------- -void plot_dat_cb(Fl_Widget *, void *v) +void plot_dat_cb(Fl_Widget *, void *) { CmdDlg *s = &cmd_dlg; s->OK = false; diff --git a/mgllab/editor.cpp b/mgllab/editor.cpp index b89d62c..4b88a40 100644 --- a/mgllab/editor.cpp +++ b/mgllab/editor.cpp @@ -14,9 +14,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include -#include #include #include #ifdef __MWERKS__ @@ -32,15 +29,15 @@ void data_file(char *v); // Syntax highlighting stuff... Fl_Text_Buffer *stylebuf = 0; Fl_Text_Display::Style_Table_Entry styletable[] = { // Style table - { FL_BLACK, FL_COURIER, 14 }, // A - Plain - { FL_DARK_GREEN,FL_COURIER_ITALIC, 14 }, // B - Line comments - { FL_BLUE, FL_COURIER, 14 }, // C - Number - { FL_RED, FL_COURIER, 14 }, // D - Strings - { FL_DARK_BLUE, FL_COURIER_BOLD, 14 }, // E - Usual ommand - { FL_DARK_CYAN, FL_COURIER_BOLD, 14 }, // F - Flow command - { FL_DARK_MAGENTA, FL_COURIER_BOLD,14 }, // G - New-data command - { FL_DARK_RED, FL_COURIER_BOLD, 14 }, // H - Option - { FL_DARK_GREEN,FL_COURIER_BOLD, 14 }}; // I - Inactive command + { FL_BLACK, FL_COURIER, 14, 0 }, // A - Plain + { FL_DARK_GREEN,FL_COURIER_ITALIC, 14, 0 }, // B - Line comments + { FL_BLUE, FL_COURIER, 14, 0 }, // C - Number + { FL_RED, FL_COURIER, 14, 0 }, // D - Strings + { FL_DARK_BLUE, FL_COURIER_BOLD, 14, 0 }, // E - Usual ommand + { FL_DARK_CYAN, FL_COURIER_BOLD, 14, 0 }, // F - Flow command + { FL_DARK_MAGENTA, FL_COURIER_BOLD,14, 0 }, // G - New-data command + { FL_DARK_RED, FL_COURIER_BOLD, 14, 0 }, // H - Option + { FL_DARK_GREEN,FL_COURIER_BOLD, 14, 0 }}; // I - Inactive command //----------------------------------------------------------------------------- bool is_sfx(const char *s) // suffix { @@ -96,7 +93,7 @@ char is_cmd(const char *s) // command } //----------------------------------------------------------------------------- // Parse text and produce style data. -void style_parse(const char *text, char *style, int length) +void style_parse(const char *text, char *style, int /*length*/) { register long i; long n=strlen(text); diff --git a/mgllab/grid.cpp b/mgllab/grid.cpp index 9702382..3c32945 100644 --- a/mgllab/grid.cpp +++ b/mgllab/grid.cpp @@ -19,10 +19,6 @@ #include #include #include -#include -#include - -#include #include "udav.h" //----------------------------------------------------------------------------- Fl_Callback input_cb; diff --git a/mgllab/help.cpp b/mgllab/help.cpp index 3e2bb44..012031c 100644 --- a/mgllab/help.cpp +++ b/mgllab/help.cpp @@ -15,9 +15,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "udav.h" -#include -#include -#include #include #include //----------------------------------------------------------------------------- diff --git a/mgllab/main.cpp b/mgllab/main.cpp index 4adbfb7..3f94e74 100644 --- a/mgllab/main.cpp +++ b/mgllab/main.cpp @@ -14,9 +14,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include -#include #include #include #include diff --git a/mgllab/mathgl.cpp b/mgllab/mathgl.cpp index 483c9db..f32b001 100644 --- a/mgllab/mathgl.cpp +++ b/mgllab/mathgl.cpp @@ -14,7 +14,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include "mgl2/mgl.h" #include "udav.h" //----------------------------------------------------------------------------- @@ -48,7 +47,7 @@ void get_doc_dir(char *&docdir); //----------------------------------------------------------------------------- void udav_error(const char *Message, void *v) { ((Fl_MGL*)v)->status->label(Message); } -float udav_delay(void *v) +mreal udav_delay(void *v) { return ((Fl_MGL*)v)->AnimDelay; } void udav_reload(void *v) { Parse->RestoreOnce(); ((Fl_MGL*)v)->update(); } @@ -87,13 +86,13 @@ Fl_MGL::Fl_MGL(int x, int y, int w, int h, char *label) : Fl_MGLView(x,y,w,h,lab script = script_pre = 0; par = this; next = udav_next; delay = udav_delay; prev = udav_prev; reload = udav_reload; -#ifdef WIN32 +/*#ifdef WIN32 // setlocale(LC_TYPE,"russian_Russia.CP1251"); char *path; get_doc_dir(path); - if(!graph->LoadFont("STIX",path && path[0] ? path : ".")) graph->RestoreFont(); + if(!FMGL->GetFont()->Load("STIX",path && path[0] ? path : ".")) FMGL->GetFont()->Restore(); free(path); -#endif +#endif*/ } //----------------------------------------------------------------------------- Fl_MGL::~Fl_MGL() { clear_scripts(); if(ArgBuf) delete []ArgBuf; } @@ -109,8 +108,9 @@ void Fl_MGL::scripts(char *scr, char *pre) //----------------------------------------------------------------------------- int Fl_MGL::Draw(mglGraph *gr) { - Parse->Execute(gr,script_pre,udav_error); - Parse->Execute(gr,script,udav_error); + Parse->Execute(gr,script_pre); + Parse->Execute(gr,script); + status->label(gr->Message()); return 0; } //----------------------------------------------------------------------------- diff --git a/mgllab/setup.cpp b/mgllab/setup.cpp index 01a20c5..f6304e4 100644 --- a/mgllab/setup.cpp +++ b/mgllab/setup.cpp @@ -298,7 +298,7 @@ void setup_cb(Fl_Widget *, void *d) } //----------------------------------------------------------------------------- Fl_Menu_Item colors[] = { - {"-----"}, // + {"-----", 0,0,0,0,0,0,0, 0}, // {("white"), 0,0,0,0,0,0,0, fl_rgb_color(0,0,0)}, //w {("blue"), 0,0,0,0,0,0,0, fl_rgb_color(0,0,255)}, //b {("lime"), 0,0,0,0,0,0,0, fl_rgb_color(0,255,0)}, //g @@ -329,7 +329,7 @@ Fl_Menu_Item colors[] = { {("brown"), 0,0,0,0,0,0,0, fl_rgb_color(127,77,0)}, //Q {("darkpink"), 0,0,0,0,0,0,0, fl_rgb_color(127,0,77)}, //P {("darkgray"), 0,0,0,0,0,0,0, fl_rgb_color(77,77,77)}, //H -{0}}; +{0, 0,0,0,0,0,0,0, 0}}; //----------------------------------------------------------------------------- struct PropDlg { diff --git a/mgllab/udav.h b/mgllab/udav.h index 737483e..2a0fe67 100644 --- a/mgllab/udav.h +++ b/mgllab/udav.h @@ -121,7 +121,7 @@ public: const char *AnimBuf; ///< buffer for animation const char **AnimS0; int AnimNum; - float AnimDelay; + mreal AnimDelay; Fl_MGL(int x, int y, int w, int h, char *label=0); ~Fl_MGL(); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1acfd73..2e844cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,32 +1,34 @@ set(mgl_src -addon.cpp axis.cpp base_cf.cpp base.cpp canvas_cf.cpp canvas.cpp cont.cpp crust.cpp -data.cpp data_io.cpp data_new.cpp data_op.cpp data_png.cpp def_font.cpp -export_2d.cpp export_3d.cpp eval.cpp evalp.cpp exec.cpp export.cpp -fit.cpp font.cpp other.cpp parser.cpp pde.cpp pixel.cpp -plot.cpp prim.cpp surf.cpp tex_table.cpp vect.cpp volume.cpp evalc.cpp #window.cpp + addon.cpp axis.cpp base_cf.cpp base.cpp canvas_cf.cpp canvas.cpp cont.cpp crust.cpp + data.cpp data_io.cpp data_new.cpp data_png.cpp def_font.cpp + export_2d.cpp export_3d.cpp eval.cpp evalp.cpp exec.cpp export.cpp + fit.cpp font.cpp other.cpp parser.cpp pde.cpp pixel.cpp + plot.cpp prim.cpp surf.cpp tex_table.cpp vect.cpp volume.cpp evalc.cpp + s_hull/s_hull_pro.cpp ) set(mgl_hdr -../include/mgl2/base_cf.h ../include/mgl2/fit.h ../include/mgl2/plot.h -../include/mgl2/base.h ../include/mgl2/prim.h ../include/mgl2/canvas_cf.h -../include/mgl2/font.h ../include/mgl2/canvas.h ../include/mgl2/surf.h -../include/mgl2/mgl_cf.h ../include/mgl2/type.h ${MathGL_BINARY_DIR}/include/mgl2/config.h -../include/mgl2/cont.h ../include/mgl2/mgl.h ../include/mgl2/vect.h -../include/mgl2/data.h ../include/mgl2/volume.h ../include/mgl2/data_cf.h -../include/mgl2/define.h ../include/mgl2/other.h ../include/mgl2/eval.h -../include/mgl2/parser.h ../include/mgl2/addon.h ../include/mgl2/evalc.h ) - -set(prc_src -prc/PRCbitStream.cc prc/PRCdouble.cc prc/oPRCFile.cc prc/writePRC.cc prc.cpp + ../include/mgl2/base_cf.h ../include/mgl2/fit.h ../include/mgl2/plot.h + ../include/mgl2/base.h ../include/mgl2/prim.h ../include/mgl2/canvas_cf.h + ../include/mgl2/font.h ../include/mgl2/canvas.h ../include/mgl2/surf.h + ../include/mgl2/mgl_cf.h ../include/mgl2/type.h ${MathGL_BINARY_DIR}/include/mgl2/config.h + ../include/mgl2/cont.h ../include/mgl2/mgl.h ../include/mgl2/vect.h + ../include/mgl2/data.h ../include/mgl2/volume.h ../include/mgl2/data_cf.h + ../include/mgl2/define.h ../include/mgl2/other.h ../include/mgl2/eval.h + ../include/mgl2/parser.h ../include/mgl2/addon.h ../include/mgl2/evalc.h + s_hull/s_hull_pro.h ) -set(prc_hdr -prc/PRC.h prc/PRCbitStream.h prc/PRCdouble.h prc/oPRCFile.h prc/writePRC.h -) +add_definitions(-DMGL_SRC) + +if(MGL_HAVE_PNG) + set(prc_src prc/PRCbitStream.cc prc/PRCdouble.cc prc/oPRCFile.cc prc/writePRC.cc prc.cpp ) + set(prc_hdr prc/PRC.h prc/PRCbitStream.h prc/PRCdouble.h prc/oPRCFile.h prc/writePRC.h ) -set(mgl_src ${mgl_src} ${prc_src} ) -set(mgl_hdr ${mgl_hdr} ${prc_hdr} ) -include_directories(prc) + set(mgl_src ${mgl_src} ${prc_src} ) + set(mgl_hdr ${mgl_hdr} ${prc_hdr} ) + include_directories(prc) +endif(MGL_HAVE_PNG) if(MGL_HAVE_OPENGL) set(mgl_src ${mgl_src} opengl.cpp ) @@ -93,8 +95,23 @@ if(MGL_HAVE_OPENGL) include_directories(${OPENGL_INCLUDE_DIR} ) endif(MGL_HAVE_OPENGL) -target_link_libraries(mgl ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} m) -include_directories(${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}) +if(MGL_HAVE_PNG) + target_link_libraries(mgl ${PNG_LIBRARIES} ) + include_directories(${PNG_INCLUDE_DIR}) +endif(MGL_HAVE_PNG) + +if(MGL_HAVE_ZLIB) + target_link_libraries(mgl ${ZLIB_LIBRARIES} ) + include_directories(${ZLIB_INCLUDE_DIR}) +endif(MGL_HAVE_ZLIB) + +if(MGL_HAVE_MPI) + target_link_libraries(mgl ${MPI_LIBRARIES} ) +# include_directories(${MPI_C_INCLUDE_PATH}) + include_directories(${MPI_CXX_INCLUDE_PATH}) +endif(MGL_HAVE_MPI) + +target_link_libraries(mgl ${M_LIB}) file(TO_NATIVE_PATH $(MGL_FONT_PATH) MGL_FONT_PATH_SYS) #add_definitions(-DMGL_FONT_PATH="${MGL_FONT_PATH_SYS}") diff --git a/src/addon.cpp b/src/addon.cpp index b771942..140c24a 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -74,7 +74,7 @@ char *mgl_fgetstr(FILE *fp) return s; } //--------------------------------------------------------------------------- -bool mgl_istrue(char ch) +int mgl_istrue(char ch) { return (ch=='1' || ch=='t' || ch=='+' || ch=='v'); } //--------------------------------------------------------------------------- void mgl_test(const char *str, ...) @@ -134,7 +134,7 @@ FILE *mgl_next_data(const char *fname,int p) return fp; } //--------------------------------------------------------------------------- -bool mglDifrGrid(dual *a,int n,dual q,int Border,dual *b,dual *d,int kk) +bool mgl_difr_grid(dual *a,int n,dual q,int Border,dual *b,dual *d,int kk) { register int i,k; // if(n<=0 || q>=0.5) return false; @@ -174,7 +174,7 @@ bool mglDifrGrid(dual *a,int n,dual q,int Border,dual *b,dual *d,int kk) return true; } //---------------------------------------------------------------------------- -bool mglDifrAxial(dual *a, int n, dual q, int Border,dual *b, dual *d, int kk, double di) +bool mgl_difr_axial(dual *a, int n, dual q, int Border,dual *b, dual *d, int kk, double di) { register int i,k,ii = di<0 ? -int(floor(di)) : 0; dual adt = dual(0.,1.)*q; diff --git a/src/axis.cpp b/src/axis.cpp index c7dea0a..cccb187 100644 --- a/src/axis.cpp +++ b/src/axis.cpp @@ -18,9 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include -#include #include -#include #include "mgl2/data.h" #include "mgl2/canvas.h" #include "mgl2/prim.h" @@ -28,9 +26,9 @@ #define islog(a, b) (((a)>0 && (b)>10*(a)) || ((b)<0 && (a)<10*(b))) #define sign(a) ((a)<0 ? -1:1) //----------------------------------------------------------------------------- -inline struct tm* mgl_localtime_r (const time_t *clock, struct tm *result) +inline struct tm* mgl_localtime (const time_t *clock, struct tm *result, bool use_utc) { if (!clock || !result) return NULL; - memcpy(result,localtime(clock),sizeof(*result)); +memcpy(result,use_utc?gmtime(clock):localtime(clock),sizeof(*result)); return result; } //----------------------------------------------------------------------------- long mgl_have_color(const char *stl) @@ -52,9 +50,8 @@ void mgl_wcstrim(wchar_t *str) wchar_t *c = mgl_wcsdup(str); unsigned long n=wcslen(str); long k; - for(k=0;k' ') break; - wcscpy(c,&(str[k])); - n = wcslen(c); + for(k=0;k' ') break; + wcscpy(c,str+k); n = wcslen(c); for(k=n-1;k>=0;k--) if(c[k]>' ') break; c[k+1] = 0; wcscpy(str,c); free(c); @@ -72,10 +69,10 @@ void mglCanvas::SetAxisStl(const char *stl, const char *tck, const char *sub) else if(strlen(sub)<32) strcpy(SubTStl,sub); } //----------------------------------------------------------------------------- -void mglCanvas::SetTickLen(float tlen, float stt) +void mglCanvas::SetTickLen(mreal tlen, mreal stt) { TickLen = tlen?tlen:0.02; st_t=stt>0?stt:1; } //----------------------------------------------------------------------------- -void mglCanvas::SetTicks(char dir, float d, int ns, float org) +void mglCanvas::SetTicks(char dir, mreal d, int ns, mreal org) { if(!strchr("xyzca",dir)) return; mglAxis &aa = (dir=='x' ? ax : (dir=='y' ? ay : (dir=='z' ? az : ac))); @@ -196,9 +193,9 @@ void mglCanvas::SetTickTempl(char dir, const char *t) else if(strlen(t)<255) mbstowcs(aa.t,t,strlen(t)+1); } //----------------------------------------------------------------------------- -double mgl_adj_val(double v,float *ds=0) +double mgl_adj_val(double v,mreal *ds=0) { - float n = floor(log10(v)), s; + double n = floor(log10(v)), s; v = floor(v*pow(10.,-n)); n = pow(10.,n); if(v==1) { v = n/5; s=n/10; } @@ -209,15 +206,15 @@ double mgl_adj_val(double v,float *ds=0) return v; } //----------------------------------------------------------------------------- -void mglCanvas::SetTickTime(char dir, float d, const char *t) +void mglCanvas::SetTickTime(char dir, mreal d, const char *t) { if(!strchr("xyzca",dir)) return; mglAxis &aa = (dir=='x' ? ax : (dir=='y' ? ay : (dir=='z' ? az : ac))); UpdateAxis(); time_t tt; tm t1,t2; - tt=aa.v1; mgl_localtime_r(&tt,&t1); - tt=aa.v2; mgl_localtime_r(&tt,&t2); + tt=aa.v1; mgl_localtime(&tt, &t1, get(MGL_USE_GMTIME)); + tt=aa.v2; mgl_localtime(&tt, &t2, get(MGL_USE_GMTIME)); if(aa.v11 ? "%x" : "%X"; - if(fabs(t1.tm_year-t2.tm_year)>3) t = "%Y"; + t = abs(t1.tm_yday-t2.tm_yday)>1 ? "%x" : "%X"; + if(abs(t1.tm_year-t2.tm_year)>3) t = "%Y"; } if(d==0) // try to select opimal step { - if(fabs(t1.tm_year-t2.tm_year)>1) - d = 365.25*24*3600*mgl_adj_val(fabs(t1.tm_year-t2.tm_year)); // number of second in year NOTE: improve it + if(abs(t1.tm_year-t2.tm_year)>1) + d = 365.25*24*3600*mgl_adj_val(abs(t1.tm_year-t2.tm_year)); // number of second in year NOTE: improve it // NOTE here should be months ... but it is too unregular ... so omit it now // else if(t1.tm_mon!=t2.tm_mon) d = 30*24*3600; // number of second in month - else if(fabs(t1.tm_yday-t2.tm_yday)>1) // localtime("%x") cannot print time < 1 day - { d = 24*3600*mgl_adj_val(fabs(t1.tm_yday-t2.tm_yday)); d = d>24*3600?d:24*3600; } - else if(fabs(t1.tm_hour-t2.tm_hour)>1) - d = 3600*mgl_adj_val(fabs(t1.tm_hour-t2.tm_hour)); - else if(fabs(t1.tm_min-t2.tm_min)>1) - d = 60*mgl_adj_val(fabs(t1.tm_min-t2.tm_min)); - else if(fabs(t1.tm_sec-t2.tm_sec)>1) // localtime("%X") cannot print time < 1 sec - { d = mgl_adj_val(fabs(t1.tm_sec-t2.tm_sec)); d = d>1?d:1; } + else if(abs(t1.tm_yday-t2.tm_yday)>1) // localtime("%x") cannot print time < 1 day + { d = 24*3600.*mgl_adj_val(abs(t1.tm_yday-t2.tm_yday)); d = d>24*3600?d:24*3600; } + else if(abs(t1.tm_hour-t2.tm_hour)>1) + d = 3600.*mgl_adj_val(abs(t1.tm_hour-t2.tm_hour)); + else if(abs(t1.tm_min-t2.tm_min)>1) + d = 60*mgl_adj_val(abs(t1.tm_min-t2.tm_min)); + else if(abs(t1.tm_sec-t2.tm_sec)>1) // localtime("%X") cannot print time < 1 sec + { d = mgl_adj_val(abs(t1.tm_sec-t2.tm_sec)); d = d>1?d:1; } else // adjust msec. NOTE: this is not supported by localtime() !!! d = mgl_adj_val(fabs(aa.v2-aa.v1)); + aa.ds = 0; } aa.dv = d; aa.f = 1; aa.txt.clear(); @@ -266,14 +264,14 @@ void mglCanvas::SetTickTime(char dir, float d, const char *t) if(aa.ch=='z') aa.v0 = aa.org.z; wchar_t buf[64]; - float v, v0 = mgl_isnan(aa.o) ? aa.v0 : aa.o, v1; + mreal v, v0 = mgl_isnan(aa.o) ? aa.v0 : aa.o, v1; if(aa.v2>aa.v1) { v1 = aa.v2; v0 = v0 - aa.dv*floor((v0-aa.v1)/aa.dv+1e-3); } else { v1 = aa.v1; v0 = v0 - aa.dv*floor((v0-aa.v2)/aa.dv+1e-3); } if(v0+aa.dv!=v0 && v1+aa.dv!=v1) for(v=v0;v<=v1;v+=aa.dv) { - tt = v; tm tp; mgl_localtime_r(&tt,&tp); + tt = v; tm tp; mgl_localtime(&tt, &tp, get(MGL_USE_GMTIME)); wcsftime(buf,64,aa.t,&tp); aa.AddLabel(buf,v); } } @@ -294,12 +292,12 @@ void mglCanvas::AdjustTicks(const char *dir, bool force) //----------------------------------------------------------------------------- void mglCanvas::AdjustTicks(mglAxis &aa, bool ff) { - float d = fabs(aa.v2-aa.v1), n; + double d = fabs(aa.v2-aa.v1), n; if(aa.f>0) return; if(ff && islog(aa.v1,aa.v2)) { aa.dv = 0; aa.ds=0; } else if(aa.d>0) - { aa.dv = aa.d; aa.ds = aa.d/(fabs(aa.ns)+1); } + { aa.dv = aa.d; aa.ds = aa.d/(abs(aa.ns)+1); } else if(aa.d>-1.5) // like =0 or =-1 { aa.dv = mgl_adj_val(d,&aa.ds); aa.o=0; } else @@ -312,7 +310,7 @@ void mglCanvas::AdjustTicks(mglAxis &aa, bool ff) LabelTicks(aa); } //----------------------------------------------------------------------------- -int mgl_tick_ext(float a, float b, wchar_t s[32], float &v) +int mgl_tick_ext(mreal a, mreal b, wchar_t s[32], mreal &v) { int kind = 0; if(fabs(a-b)<=0.001*fabs(a)) @@ -353,9 +351,9 @@ int mgl_tick_ext(float a, float b, wchar_t s[32], float &v) return kind; } //----------------------------------------------------------------------------- -void mgl_tick_text(float z, float z0, float d, float v, int kind, wchar_t str[64], bool tune) +void mgl_tick_text(mreal z, mreal z0, mreal d, mreal v, int kind, wchar_t str[64], bool tune) { - float u = fabs(z)z0) u = fabs(z-z0)z0)) u /= v; if((kind&1) && z>z0) @@ -384,8 +382,8 @@ void mglCanvas::LabelTicks(mglAxis &aa) if(aa.ch=='y') aa.v0 = aa.org.y; if(aa.ch=='z') aa.v0 = aa.org.z; - wchar_t buf[64]; - float v,v0,v1,w; + wchar_t buf[64]=L""; + mreal v,v0,v1,w; int d,ds; if(aa.f) return; aa.txt.clear(); @@ -393,7 +391,7 @@ void mglCanvas::LabelTicks(mglAxis &aa) { v0 = exp(M_LN10*floor(0.1+log10(aa.v1))); ds = int(floor(0.1+log10(aa.v2/v0))/7)+1; - for(v=v0;v<=aa.v2*MGL_FLT_EPS;v*=10) if(v*MGL_FLT_EPS>=aa.v1) + for(v=v0;v<=aa.v2*MGL_EPSILON;v*=10) if(v*MGL_EPSILON>=aa.v1) { d = int(floor(0.1+log10(v))); if(d==0) wcscpy(buf,L"1"); @@ -407,7 +405,7 @@ void mglCanvas::LabelTicks(mglAxis &aa) { v0 = -exp(M_LN10*floor(0.1+log10(-aa.v2))); ds = int(floor(0.1+log10(aa.v1/v0))/7)+1; - for(v=v0;v>=aa.v1*MGL_FLT_EPS;v*=10) if(v*MGL_FLT_EPS<=aa.v2) + for(v=v0;v>=aa.v1*MGL_EPSILON;v*=10) if(v*MGL_EPSILON<=aa.v2) { d = int(floor(0.1+log10(-v))); if(d==0) wcscpy(buf,L"-1"); @@ -453,6 +451,8 @@ void mglCanvas::Axis(const char *dir, const char *stl) if(strchr(dir,ar[i])) { arr=ar[i]; break; } bool adjust = stl && strchr(stl,'a'); + bool ret = get(MGL_ENABLE_RTEXT); + if(dir && strchr(dir,'U')) clr(MGL_ENABLE_RTEXT); AdjustTicks(dir,adjust); // TODO: Ternary axis labeling ... if(strchr(dir,'x')) DrawAxis(ax, text, arr, stl); @@ -466,6 +466,7 @@ void mglCanvas::Axis(const char *dir, const char *stl) DrawAxis(ty, text, arr, stl); } else if(strchr(dir,'y')) DrawAxis(ay, text, arr, stl); + set(ret, MGL_ENABLE_RTEXT); } //----------------------------------------------------------------------------- void mglCanvas::DrawAxis(mglAxis &aa, bool text, char arr,const char *stl) @@ -501,7 +502,7 @@ void mglCanvas::DrawAxis(mglAxis &aa, bool text, char arr,const char *stl) } k2 = aa.txt.size(); - float v, u, v0 = mgl_isnan(aa.o) ? aa.v0 : aa.o; + mreal v, u, v0 = mgl_isnan(aa.o) ? aa.v0 : aa.o; if(k2>0) for(i=0;i0) + if(aa.ds>0 && !get(MGL_NOSUBTICKS)) { if(aa.v2>aa.v1) v0 = v0 - aa.ds*floor((v0-aa.v1)/aa.ds+1e-3); else v0 = v0 - aa.ds*floor((v0-aa.v2)/aa.ds+1e-3); @@ -535,7 +536,7 @@ void mglCanvas::DrawLabels(mglAxis &aa) // if(get(MGL_DISABLE_SCALE) && ((aa.dir.x==0 && aa.org.x<0) || (aa.dir.y==0 && aa.org.y>0))) pos[0]='T'; if(aa.ch=='c') pos[0]=(aa.ns==0 || aa.ns==3)?'t':'T'; if(aa.ch=='T') pos[0]='T'; - float *w=new float[n], h = TextHeight(FontDef,-1)/4, c=NAN, l=NAN, tet=0, v, vv; // find sizes + mreal *w=new mreal[n], h = TextHeight(FontDef,-1)/3, c=NAN, l=NAN, tet=0, v, vv; // find sizes long *kk=new long[n]; for(i=0;iaa.v1 && c0) ? 'T':'t'; if(aa.ch=='T' && pos[0]=='T') pos[0]='t'; if(aa.ch=='T' && pos[0]=='t') pos[0]='T'; - text_plot(kk[i], aa.txt[i].text.c_str(), pos, -1, 0.07,CDef,tet?false:true); + text_plot(kk[i], aa.txt[i].text.c_str(), pos, -1, aa.sh+0.07,CDef,tet?false:true); } delete []w; delete []kk; } @@ -587,7 +587,7 @@ void mglCanvas::tick_draw(mglPoint o, mglPoint d1, mglPoint d2, int f, const cha // try to exclude ticks out of axis range if(f && ((o.x-Min.x)*(o.x-Max.x)>0 || (o.y-Min.y)*(o.y-Max.y)>0 || (o.z-Min.z)*(o.z-Max.z)>0)) return; - float v = font_factor*TickLen/sqrt(1+f*st_t); + mreal v = font_factor*TickLen/sqrt(1.f+f*st_t); mglPoint p=o; long k1,k2,k3=mgl_have_color(stl); @@ -624,7 +624,7 @@ void mglCanvas::DrawGrid(mglAxis &aa) oa = aa.b*(aa.b*aa.org); ob = aa.a*(aa.a*aa.org); register long i,j,n=aa.txt.size(),k1,k2; - float v; + mreal v; Reserve(62*n); if(n>0) for(i=0;i')) { x=in?(1+s)/2:1; y=0; } if(sch && strchr(sch,'<')) { x=in?(1-s)/2:0; y=0; } if(sch && strchr(sch,'^')) { x=0; y=in?(1+s)/2:1; } @@ -807,7 +785,7 @@ void mglCanvas::Colorbar(const char *sch) Colorbar(sch, x, y, 1, 1); } //----------------------------------------------------------------------------- -void mglCanvas::Colorbar(const char *sch, float x, float y, float w, float h) +void mglCanvas::Colorbar(const char *sch, mreal x, mreal y, mreal w, mreal h) { bool in = sch && strchr(sch,'I'); int where = 0; // ‘0’ - right, ‘1’ - left, ‘2’ - above, ‘3’ - under @@ -824,7 +802,7 @@ void mglCanvas::Colorbar(const char *sch, float x, float y, float w, float h) { v.Fill(log(Min.c), log(Max.c)); v.Modify("exp(u)"); } else if(Min.c')) { x=in?(1+s)/2:1; y=0; } if(sch && strchr(sch,'<')) { x=in?(1-s)/2:0; y=0; } if(sch && strchr(sch,'^')) { x=0; y=in?(1+s)/2:1; } @@ -842,7 +820,7 @@ void mglCanvas::Colorbar(HCDT v, const char *sch) Colorbar(v, sch, x, y, 1, 1); } //----------------------------------------------------------------------------- -void mglCanvas::Colorbar(HCDT v, const char *sch, float x, float y, float w, float h) +void mglCanvas::Colorbar(HCDT v, const char *sch, mreal x, mreal y, mreal w, mreal h) { bool in = sch && strchr(sch,'I'); int where = 0; @@ -852,23 +830,23 @@ void mglCanvas::Colorbar(HCDT v, const char *sch, float x, float y, float w, flo if(sch && strchr(sch,'_')) where = in?2:3; if(sch && strchr(sch,'A')) { Push(); Identity(); } - float *c=new float[v->GetNx()]; + mreal *c=new mreal[v->GetNx()]; if(!mgl_have_color(sch)) sch = MGL_DEF_PAL; long s = AddTexture(sch); int nc = GetNumPal(s*256); - float dc = nc>1 ? 1/(MGL_FLT_EPS*(nc-1)):0; + mreal dc = nc>1 ? 1/(MGL_EPSILON*(nc-1)):0; for(long i=0;iGetNx();i++) c[i] = s+i*dc; colorbar(v, c, where, x, y, w, h); delete []c; if(sch && strchr(sch,'A')) Pop(); } //----------------------------------------------------------------------------- -void mglCanvas::colorbar(HCDT vv, const float *c, int where, float x, float y, float w, float h) +void mglCanvas::colorbar(HCDT vv, const mreal *c, int where, mreal x, mreal y, mreal w, mreal h) { static int cgid=1; StartGroup("Colorbar",cgid++); register unsigned long i,n=vv->GetNx(); long n1,n2,n3,n4; - float d,s3=B.pf,ss=1/s3; // NOTE: colorbar was wider ss=0.9; + mreal d,s3=B.pf,ss=1/s3; // NOTE: colorbar was wider ss=0.9; mglPoint p1,p2; Push(); set(MGL_DISABLE_SCALE); B=B1; B.pf=s3; @@ -909,7 +887,7 @@ void mglCanvas::colorbar(HCDT vv, const float *c, int where, float x, float y, f } else { UpdateAxis(); AdjustTicks(ac,fa); } // hint for using standard label drawing function - float cc=AddTexture('k'); + mreal cc=AddTexture('k'); for(i=0;i #include "mgl2/base.h" #include "mgl2/define.h" //----------------------------------------------------------------------------- @@ -60,7 +59,7 @@ mglBase::mglBase() fnt=0; *FontDef=0; fx=fy=fz=fa=fc=0; - InUse = 1; + InUse = 1; SetQuality(); // Always create default palette txt[0] and default scheme txt[1] Txt.reserve(3); Txt.push_back(mglTexture(MGL_DEF_PAL,-1)); @@ -70,7 +69,7 @@ mglBase::mglBase() } mglBase::~mglBase() { ClearEq(); } //----------------------------------------------------------------------------- -float mglBase::GetRatio() const { return 1; } +mreal mglBase::GetRatio() const { return 1; } //----------------------------------------------------------------------------- void mglBase::StartGroup(const char *name, int id) { @@ -103,19 +102,20 @@ void mglBase::SetWarn(int code, const char *who) WarnCode = code>0 ? code:0; if(code>0 && code0) ScalePoint(p,n,!(scl&2)); if(mgl_isnan(p.x)) return -1; a = (a>=0 && a<=1) ? a : AlphaDef; @@ -133,19 +133,25 @@ long mglBase::AddPnt(mglPoint p, float c, mglPoint n, float a, int scl) q.x=q.xx=p.x; q.y=q.yy=p.y; q.z=q.zz=p.z; q.c=c; q.t=q.ta=a; q.u=n.x; q.v=n.y; q.w=n.z; } -// q.x=q.xx=int(p.x*100)*0.01; q.y=q.yy=p.y; q.z=q.zz=p.z; -// q.c=c; q.t=q.ta=a; q.u=n.x; q.v=n.y; q.w=n.z; - const mglTexture &txt=Txt[long(c)]; + register long ci=long(c); + if(ci<0 || ci>=Txt.size()) ci=0; // NOTE never should be here!!! + const mglTexture &txt=Txt[ci]; txt.GetC(c,a,q); // RGBA color - if(!get(MGL_ENABLE_ALPHA)) { q.a=1; if(txt.Smooth!=2) q.ta=1; } - if(q.ta<0.005) q.ta = 0.005; // bypass OpenGL/OBJ/PRC bug + // add gap for texture coordinates for compatibility with OpenGL + const mreal gap = 1./512; + q.c = ci+(q.c-ci)*(1-2*gap)+gap; + q.t = q.t*(1-2*gap)+gap; + q.ta = q.t; + + if(!get(MGL_ENABLE_ALPHA)) { q.a=1; if(txt.Smooth!=2) q.ta=1-gap; } +// if(q.ta<0.005) q.ta = 0.005; // bypass OpenGL/OBJ/PRC bug if(scl&8 && scl>0) q.a=a; // bypass palette for enabling alpha in Error() if(!get(MGL_ENABLE_LIGHT) && !(scl&4)) q.u=q.v=NAN; MGL_PUSH(Pnt,q,mutexPnt); return Pnt.size()-1; } //----------------------------------------------------------------------------- -long mglBase::CopyNtoC(long from, float c) +long mglBase::CopyNtoC(long from, mreal c) { if(from<0) return -1; mglPnt p=Pnt[from]; @@ -178,7 +184,7 @@ void mglBase::RecalcCRange() { FMin.c = 1e30; FMax.c = -1e30; register int i; - float a; + mreal a; int n=30; for(i=0;i<=n;i++) { @@ -191,7 +197,8 @@ void mglBase::RecalcCRange() //----------------------------------------------------------------------------- void mglBase::RecalcBorder() { - if(!fx && !fy && !fz) + ZMin = 1.; + if(!fx && !fy && !fz) { FMin = Min; FMax = Max; } else { @@ -214,7 +221,7 @@ void mglBase::RecalcBorder() SetFBord(Min.x+i*(Max.x-Min.x)/n, Min.y+j*(Max.y-Min.y)/n, Min.x); SetFBord(Min.x+i*(Max.x-Min.x)/n, Min.y+j*(Max.y-Min.y)/n, Max.z); } - float d; + mreal d; if(!fx) { FMin.x = Min.x; FMax.x = Max.x; } else { d=0.01*(FMax.x-FMin.x); FMin.x-=d; FMax.x+=d; } if(!fy) { FMin.y = Min.y; FMax.y = Max.y; } @@ -225,23 +232,23 @@ void mglBase::RecalcBorder() RecalcCRange(); } //----------------------------------------------------------------------------- -void mglBase::SetFBord(float x,float y,float z) +void mglBase::SetFBord(mreal x,mreal y,mreal z) { if(fx) { - float v = fx->Calc(x,y,z); + mreal v = fx->Calc(x,y,z); if(FMax.x < v) FMax.x = v; if(FMin.x > v) FMin.x = v; } if(fy) { - float v = fy->Calc(x,y,z); + mreal v = fy->Calc(x,y,z); if(FMax.y < v) FMax.y = v; if(FMin.y > v) FMin.y = v; } if(fz) { - float v = fz->Calc(x,y,z); + mreal v = fz->Calc(x,y,z); if(FMax.z < v) FMax.z = v; if(FMin.z > v) FMin.z = v; } @@ -249,12 +256,12 @@ void mglBase::SetFBord(float x,float y,float z) //----------------------------------------------------------------------------- bool mglBase::ScalePoint(mglPoint &p, mglPoint &n, bool use_nan) const { - float &x=p.x, &y=p.y, &z=p.z; + mreal &x=p.x, &y=p.y, &z=p.z; if(mgl_isnan(x) || mgl_isnan(y) || mgl_isnan(z)) { x=NAN; return false; } - float x1,y1,z1,x2,y2,z2; - x1 = x>0?x*MGL_FLT_EPS:x/MGL_FLT_EPS; x2 = x<0?x*MGL_FLT_EPS:x/MGL_FLT_EPS; - y1 = y>0?y*MGL_FLT_EPS:y/MGL_FLT_EPS; y2 = y<0?y*MGL_FLT_EPS:y/MGL_FLT_EPS; - z1 = z>0?z*MGL_FLT_EPS:z/MGL_FLT_EPS; z2 = z<0?z*MGL_FLT_EPS:z/MGL_FLT_EPS; + mreal x1,y1,z1,x2,y2,z2; + x1 = x>0?x*MGL_EPSILON:x/MGL_EPSILON; x2 = x<0?x*MGL_EPSILON:x/MGL_EPSILON; + y1 = y>0?y*MGL_EPSILON:y/MGL_EPSILON; y2 = y<0?y*MGL_EPSILON:y/MGL_EPSILON; + z1 = z>0?z*MGL_EPSILON:z/MGL_EPSILON; z2 = z<0?z*MGL_EPSILON:z/MGL_EPSILON; bool res = true; if(x2>CutMin.x && x1CutMin.y && y1CutMin.z && z1Max.z) {z=Max.z; n=mglPoint(0,0,1);} } - x1=x; y1=y; z1=z; - if(fx) { x1 = fx->Calc(x,y,z); n.x *= fx->CalcD('x',x,y,z); } - if(fy) { y1 = fy->Calc(x,y,z); n.y *= fy->CalcD('y',x,y,z); } - if(fz) { z1 = fz->Calc(x,y,z); n.z *= fz->CalcD('z',x,y,z); } - if(mgl_isnan(x1) || mgl_isnan(y1) || mgl_isnan(z1)) { x=NAN; return false; } + x1=x; y1=y; z1=z; x2=y2=z2=1; + if(fx) { x1 = fx->Calc(x,y,z); x2 = fx->CalcD('x',x,y,z); } + if(fy) { y1 = fy->Calc(x,y,z); y2 = fy->CalcD('y',x,y,z); } + if(fz) { z1 = fz->Calc(x,y,z); z2 = fz->CalcD('z',x,y,z); } + if(mgl_isnan(x1) || mgl_isnan(y1) || mgl_isnan(z1)) { x=NAN; return false; } - x = (2*x1 - FMin.x - FMax.x)/(FMax.x - FMin.x); - y = (2*y1 - FMin.y - FMax.y)/(FMax.y - FMin.y); - z = (2*z1 - FMin.z - FMax.z)/(FMax.z - FMin.z); - n.x *= 2/(FMax.x - FMin.x); - n.y *= 2/(FMax.y - FMin.y); - n.z *= 2/(FMax.z - FMin.z); - if((TernAxis&3)==1) // usual ternary axis - { - if(x+y>0) - { - if(get(MGL_ENABLE_CUT)) res = false; - else y = -x; - } - x += (y+1)/2; n.x += n.y/2; - } - else if((TernAxis&3)==2) // quaternary axis - { - if(x+y+z>-1) - { - if(get(MGL_ENABLE_CUT)) res = false; - else z = -1-y-x; - } - x += 1+(y+z)/2; y += (z+1)/3; - n.x += (n.y+n.z)/2; n.y += n.z/3; - } - if(fabs(x)>MGL_FLT_EPS) res = false; - if(fabs(y)>MGL_FLT_EPS) res = false; - if(fabs(z)>MGL_FLT_EPS) res = false; + register mreal d; // TODO: should I update normale for infinite light source (x=NAN)?!? + d = 1/(FMax.x - FMin.x); x = (2*x1 - FMin.x - FMax.x)*d; x2 *= 2*d; + d = 1/(FMax.y - FMin.y); y = (2*y1 - FMin.y - FMax.y)*d; y2 *= 2*d; + d = 1/(FMax.z - FMin.z); z = (2*z1 - FMin.z - FMax.z)*d; z2 *= 2*d; + n.x *= y2*z2; n.y *= x2*z2; n.z *= x2*y2; + if((TernAxis&3)==1) // usual ternary axis + { + if(x+y>0) + { + if(get(MGL_ENABLE_CUT)) res = false; + else y = -x; + } + x += (y+1)/2; n.x += n.y/2; + } + else if((TernAxis&3)==2) // quaternary axis + { + if(x+y+z>-1) + { + if(get(MGL_ENABLE_CUT)) res = false; + else z = -1-y-x; + } + x += 1+(y+z)/2; y += (z+1)/3; + n.x += (n.y+n.z)/2; n.y += n.z/3; + } + if(fabs(x)>MGL_EPSILON || fabs(y)>MGL_EPSILON || fabs(z)>MGL_EPSILON) res = false; if(!res && use_nan) x = NAN; // extra sign that point shouldn't be plotted return res; @@ -338,9 +342,9 @@ void mglBase::SetRanges(mglPoint m1, mglPoint m2) RecalcBorder(); } //----------------------------------------------------------------------------- -void mglBase::CRange(const mglDataA &a,bool add, float fact) +void mglBase::CRange(HCDT a,bool add, mreal fact) { - float v1=a.Minimal(), v2=a.Maximal(), dv; + mreal v1=a->Minimal(), v2=a->Maximal(), dv; dv=(v2-v1)*fact; v1 -= dv; v2 += dv; if(v1==v2) return; if(!add) { Min.c = v1; Max.c = v2; } @@ -360,9 +364,9 @@ void mglBase::CRange(const mglDataA &a,bool add, float fact) RecalcCRange(); } //----------------------------------------------------------------------------- -void mglBase::XRange(const mglDataA &a,bool add,float fact) +void mglBase::XRange(HCDT a,bool add,mreal fact) { - float v1=a.Minimal(), v2=a.Maximal(), dv; + mreal v1=a->Minimal(), v2=a->Maximal(), dv; dv=(v2-v1)*fact; v1 -= dv; v2 += dv; if(v1==v2) return; if(!add) { Min.x = v1; Max.x = v2; } @@ -382,9 +386,9 @@ void mglBase::XRange(const mglDataA &a,bool add,float fact) RecalcBorder(); } //----------------------------------------------------------------------------- -void mglBase::YRange(const mglDataA &a,bool add,float fact) +void mglBase::YRange(HCDT a,bool add,mreal fact) { - float v1=a.Minimal(), v2=a.Maximal(), dv; + mreal v1=a->Minimal(), v2=a->Maximal(), dv; dv=(v2-v1)*fact; v1 -= dv; v2 += dv; if(v1==v2) return; if(!add) { Min.y = v1; Max.y = v2; } @@ -404,9 +408,9 @@ void mglBase::YRange(const mglDataA &a,bool add,float fact) RecalcBorder(); } //----------------------------------------------------------------------------- -void mglBase::ZRange(const mglDataA &a,bool add,float fact) +void mglBase::ZRange(HCDT a,bool add,mreal fact) { - float v1=a.Minimal(), v2=a.Maximal(), dv; + mreal v1=a->Minimal(), v2=a->Maximal(), dv; dv=(v2-v1)*fact; v1 -= dv; v2 += dv; if(v1==v2) return; if(!add) { Min.z = v1; Max.z = v2; } @@ -426,7 +430,7 @@ void mglBase::ZRange(const mglDataA &a,bool add,float fact) RecalcBorder(); } //----------------------------------------------------------------------------- -void mglBase::SetAutoRanges(float x1, float x2, float y1, float y2, float z1, float z2, float c1, float c2) +void mglBase::SetAutoRanges(mreal x1, mreal x2, mreal y1, mreal y2, mreal z1, mreal z2, mreal c1, mreal c2) { if(x1!=x2) { Min.x = x1; Max.x = x2; } if(y1!=y2) { Min.y = y1; Max.y = y2; } @@ -556,7 +560,7 @@ void mglColor::Set(char p, float bright) { Set(mglColorIds[i].col, bright); break; } } //----------------------------------------------------------------------------- -void mglTexture::Set(const char *s, int smooth, float alpha) +void mglTexture::Set(const char *s, int smooth, mreal alpha) { // NOTE: New syntax -- colors are CCCCC or {CNCNCCCN}; options inside [] if(!s || !s[0]) return; @@ -596,7 +600,7 @@ void mglTexture::Set(const char *s, int smooth, float alpha) { alpha = 0.1*(s[i+1]-'0'); i++; } } for(i=0;i=0) { p=(p+1)%n; id = 256*i+p; } mglColor c = Txt[i].col[int(512*(p+0.5)/n)]; - float dif, dmin=1; + mreal dif, dmin=1; // try to find closest color for(long j=0;mglColorIds[j].id;j++) for(long k=1;k<10;k++) { @@ -753,15 +758,15 @@ char mglBase::SetPenPal(const char *p, long *Id) return mk; } //----------------------------------------------------------------------------- -float mglBase::GetA(float a) const +mreal mglBase::GetA(mreal a) const { if(fa) a = fa->Calc(0,0,0,a); a = (a-FMin.c)/(FMax.c-FMin.c); - a = (a<1?(a>0?a:0):1)/MGL_FLT_EPS; // for texture a must be <1 always!!! + a = (a<1?(a>0?a:0):1)/MGL_EPSILON; // for texture a must be <1 always!!! return a; } //----------------------------------------------------------------------------- -mglPoint GetX(const mglDataA *x, int i, int j, int k) +mglPoint GetX(HCDT x, int i, int j, int k) { k = kGetNz() ? k : 0; if(x->GetNy()>1) @@ -770,7 +775,7 @@ mglPoint GetX(const mglDataA *x, int i, int j, int k) return mglPoint(x->v(i),x->dvx(i),0); } //----------------------------------------------------------------------------- -mglPoint GetY(const mglDataA *y, int i, int j, int k) +mglPoint GetY(HCDT y, int i, int j, int k) { k = kGetNz() ? k : 0; if(y->GetNy()>1) @@ -779,7 +784,7 @@ mglPoint GetY(const mglDataA *y, int i, int j, int k) return mglPoint(y->v(j),0,y->dvx(j)); } //----------------------------------------------------------------------------- -mglPoint GetZ(const mglDataA *z, int i, int j, int k) +mglPoint GetZ(HCDT z, int i, int j, int k) { if(z->GetNy()>1) return mglPoint(z->v(i,j,k),z->dvx(i,j,k),z->dvy(i,j,k)); @@ -787,7 +792,7 @@ mglPoint GetZ(const mglDataA *z, int i, int j, int k) return mglPoint(z->v(k),0,0); } //----------------------------------------------------------------------------- -void mglBase::vect_plot(long p1, long p2, float s) +void mglBase::vect_plot(long p1, long p2, mreal s) { if(p1<0 || p2<0) return; const mglPnt &q1=Pnt[p1], &q2=Pnt[p2]; @@ -812,15 +817,18 @@ int mglFindArg(const char *str) if(str[i]=='\'') l++; if(str[i]=='{') k++; if(str[i]=='}') k--; - if(l%2==0 && k==0 && (str[i]=='#' || str[i]==';')) return -i; - if(l%2==0 && k==0 && (str[i]<=' ')) return i; + if(l%2==0 && k==0) + { + if(str[i]=='#' || str[i]==';') return -i; + if(str[i]<=' ') return i; + } } return 0; } //----------------------------------------------------------------------------- -void mglBase::SetAmbient(float bright) { AmbBr = bright; } +void mglBase::SetAmbient(mreal bright) { AmbBr = bright; } //----------------------------------------------------------------------------- -float mglBase::SaveState(const char *opt) +mreal mglBase::SaveState(const char *opt) { if(!opt || !opt[0] || saved) return NAN; MSS=MarkSize; ASS=ArrowSize; @@ -828,7 +836,7 @@ float mglBase::SaveState(const char *opt) MNS=MeshNum; CSS=Flag; LSS=AmbBr; MinS=Min; MaxS=Max; saved=true; // parse option - char *q=mgl_strdup(opt),*s,*a,*b,*c; + char *qi=mgl_strdup(opt),*q=qi, *s,*a,*b,*c; long n; mgl_strtrim(q); // NOTE: not consider '#' inside legend entry !!! @@ -843,7 +851,7 @@ float mglBase::SaveState(const char *opt) n=mglFindArg(s); if(n>0) { s[n]=0; s=s+n+1; } mgl_strtrim(b); - float ff=atof(b),ss; + mreal ff=atof(b),ss; if(!strcmp(b,"on")) ff=1; if(!strcmp(a+1,"range")) { @@ -867,7 +875,7 @@ float mglBase::SaveState(const char *opt) else if(!strcmp(a,"legend")) { if(*b=='\'') { b++; b[strlen(b)-1]=0; } leg_str = b; } } - free(q); return NAN; + free(qi); return NAN; } //----------------------------------------------------------------------------- void mglBase::LoadState() @@ -892,3 +900,84 @@ void mglBase::AddLegend(const char *str,const char *style) delete []wcs; } //----------------------------------------------------------------------------- +bool mgl_check_dim2(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *name, bool less) +{ + register long n=z->GetNx(),m=z->GetNy(); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,name); return true; } + if(a && n*m*z->GetNz()!=a->GetNx()*a->GetNy()*a->GetNz()) + { gr->SetWarn(mglWarnDim,name); return true; } + if(less) + { + if(x->GetNx()SetWarn(mglWarnDim,name); return true; } + if(y->GetNx()GetNy()GetNx()GetNy()SetWarn(mglWarnDim,name); return true; }; + } + else + { + if(x->GetNx()!=n) + { gr->SetWarn(mglWarnDim,name); return true; } + if(y->GetNx()!=m && (x->GetNy()!=m || y->GetNx()!=n || y->GetNy()!=m)) + { gr->SetWarn(mglWarnDim,name); return true; }; + } + return false; +} +//----------------------------------------------------------------------------- +bool mgl_check_dim1(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT r, const char *name, bool less) +{ + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,name); return true; } + if(less) + { + if(x->GetNx()SetWarn(mglWarnDim,name); return true; } + if(z && z->GetNx()SetWarn(mglWarnDim,name); return true; } + if(r && r->GetNx()SetWarn(mglWarnDim,name); return true; } + } + else + { + if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,name); return true; } + if(z && z->GetNx()!=n) { gr->SetWarn(mglWarnDim,name); return true; } + if(r && r->GetNx()!=n) { gr->SetWarn(mglWarnDim,name); return true; } + } + return false; +} +//----------------------------------------------------------------------------- +bool mgl_check_dim3(HMGL gr, bool both, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *name) +{ + register long n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(n<2 || m<2 || l<2) + { gr->SetWarn(mglWarnLow,name); return true; } + if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) + { gr->SetWarn(mglWarnDim,name); return true; } + if(b && b->GetNx()*b->GetNy()*b->GetNz()!=n*m*l) + { gr->SetWarn(mglWarnDim,name); return true; } + return false; +} +//----------------------------------------------------------------------------- +bool mgl_check_trig(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const char *name, int d) +{ + long n = x->GetNx(), m = nums->GetNy(); + if(nums->GetNx()SetWarn(mglWarnLow,name); return true; } + if(y->GetNx()!=n || z->GetNx()!=n) { gr->SetWarn(mglWarnDim,name); return true; } + if(a->GetNx()!=m && a->GetNx()!=n) { gr->SetWarn(mglWarnDim,name); return true; } + return false; +} +//----------------------------------------------------------------------------- +bool mgl_isboth(HCDT x, HCDT y, HCDT z, HCDT a) +{ + register long n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + return x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; +} +//----------------------------------------------------------------------------- +bool mgl_check_vec3(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *name) +{ + register long n=ax->GetNx(),m=ax->GetNy(),l=ax->GetNz(); + if(n*m*l!=ay->GetNx()*ay->GetNy()*ay->GetNz() || n*m*l!=az->GetNx()*az->GetNy()*az->GetNz()) + { gr->SetWarn(mglWarnDim,name); return true; } + if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,name); return true; } + bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; + if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) + { gr->SetWarn(mglWarnDim,name); return true; } + return false; +} +//----------------------------------------------------------------------------- diff --git a/src/base_cf.cpp b/src/base_cf.cpp index 1cb734f..deb3d4e 100644 --- a/src/base_cf.cpp +++ b/src/base_cf.cpp @@ -23,12 +23,15 @@ // C interfaces // //----------------------------------------------------------------------------- -void mgl_set_color(char id, float r, float g, float b) +int mgl_get_flag(HMGL gr, long flag) { return gr->get(flag); } +void mgl_set_flag(HMGL gr, int val, long flag) { gr->set(val,flag); } +//----------------------------------------------------------------------------- +void mgl_set_color(char id, mreal r, mreal g, mreal b) { register size_t i; for(i=0;mglColorIds[i].id;i++) if(mglColorIds[i].id==id) mglColorIds[i].col = mglColor(r,g,b); } -void mgl_set_color_(char *id, float *r, float *g, float *b, int) { mgl_set_color(*id,*r,*g,*b); } +void mgl_set_color_(char *id, mreal *r, mreal *g, mreal *b, int) { mgl_set_color(*id,*r,*g,*b); } //----------------------------------------------------------------------------- void mgl_set_def_sch(HMGL gr, const char *sch) { gr->SetDefScheme(sch); } void mgl_set_def_sch_(uintptr_t *gr, const char *sch,int l) @@ -39,23 +42,23 @@ const char *mgl_get_mess(HMGL gr) { return gr->Mess.c_str(); } int mgl_get_warn(HMGL gr) { return gr->GetWarn(); } void mgl_set_warn(HMGL gr, int code, const char *txt) { gr->SetWarn(code,txt); } -void mgl_set_origin(HMGL gr, float x0, float y0, float z0) +void mgl_set_origin(HMGL gr, mreal x0, mreal y0, mreal z0) { gr->SetOrigin(x0,y0,z0); } void mgl_set_palette(HMGL gr, const char *colors) { gr->SetPalette(colors); } void mgl_set_meshnum(HMGL gr, int num) { gr->SetMeshNum(num); } -void mgl_set_alpha_default(HMGL gr, float alpha) { gr->SetAlphaDef(alpha); } +void mgl_set_alpha_default(HMGL gr, mreal alpha) { gr->SetAlphaDef(alpha); } void mgl_set_light_dif(HMGL gr, int enable) { gr->SetDifLight(enable); } //----------------------------------------------------------------------------- void mgl_set_rdc_acc(HMGL gr, int reduce) { gr->SetReduceAcc(reduce); } void mgl_highlight(HMGL gr, int id) { gr->Highlight(id); } void mgl_set_cut(HMGL gr, int cut) { gr->SetCut(cut); } -void mgl_set_cut_box(HMGL gr, float x1,float y1,float z1,float x2,float y2,float z2) +void mgl_set_cut_box(HMGL gr, mreal x1,mreal y1,mreal z1,mreal x2,mreal y2,mreal z2) { gr->SetCutBox(x1,y1,z1,x2,y2,z2); } void mgl_set_cutoff(HMGL gr, const char *EqC) { gr->CutOff(EqC); } //----------------------------------------------------------------------------- void mgl_set_ternary(HMGL gr, int enable) { gr->Ternary(enable); } -void mgl_set_range_val(HMGL gr, char dir, float v1,float v2) +void mgl_set_range_val(HMGL gr, char dir, mreal v1,mreal v2) { if(dir=='c') gr->CRange(v1,v2); else if(dir=='x') gr->XRange(v1,v2); @@ -63,21 +66,21 @@ void mgl_set_range_val(HMGL gr, char dir, float v1,float v2) else if(dir=='z') gr->ZRange(v1,v2); } void mgl_set_range_dat(HMGL gr, char dir, HCDT a, int add) { - if(dir=='c') gr->CRange(_Da_(a),add); - else if(dir=='x') gr->XRange(_Da_(a),add); - else if(dir=='y') gr->YRange(_Da_(a),add); - else if(dir=='z') gr->ZRange(_Da_(a),add); } -void mgl_set_ranges(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2) + if(dir=='c') gr->CRange(a,add); + else if(dir=='x') gr->XRange(a,add); + else if(dir=='y') gr->YRange(a,add); + else if(dir=='z') gr->ZRange(a,add); } +void mgl_set_ranges(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2) { gr->SetRanges(x1,y1,z1,x2,y2,z2); } void mgl_set_func(HMGL gr, const char *EqX,const char *EqY,const char *EqZ,const char *EqA) { gr->SetFunc(EqX,EqY,EqZ,EqA); } void mgl_set_coor(HMGL gr, int how) { gr->SetCoor(how); } //----------------------------------------------------------------------------- -long mgl_data_get_nx(HCDT d) { return _Da_(d).GetNx(); } -long mgl_data_get_ny(HCDT d) { return _Da_(d).GetNy(); } -long mgl_data_get_nz(HCDT d) { return _Da_(d).GetNz(); } +long mgl_data_get_nx(HCDT d) { return d->GetNx(); } +long mgl_data_get_ny(HCDT d) { return d->GetNy(); } +long mgl_data_get_nz(HCDT d) { return d->GetNz(); } //----------------------------------------------------------------------------- -void mgl_set_bar_width(HMGL gr, float width) { gr->SetBarWidth(width); } +void mgl_set_bar_width(HMGL gr, mreal width) { gr->SetBarWidth(width); } //----------------------------------------------------------------------------- // // Fortran interfaces @@ -86,7 +89,7 @@ void mgl_set_bar_width(HMGL gr, float width) { gr->SetBarWidth(width); } void mgl_set_rdc_acc_(uintptr_t *gr, int *reduce) { _GR_->SetReduceAcc(*reduce); } void mgl_highlight_(uintptr_t *gr, int *id) { _GR_->Highlight(*id); } -void mgl_set_origin_(uintptr_t *gr, float *x0, float *y0, float *z0) +void mgl_set_origin_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0) { _GR_->SetOrigin(*x0,*y0,*z0); } int mgl_get_warn_(uintptr_t *gr) { return _GR_->GetWarn(); } void mgl_set_warn_(uintptr_t *gr, int *code, const char *txt, int l) @@ -96,10 +99,10 @@ void mgl_set_palette_(uintptr_t *gr, const char *colors, int l) { char *s=new char[l+1]; memcpy(s,colors,l); s[l]=0; _GR_->SetPalette(s); delete []s; } void mgl_set_meshnum_(uintptr_t *gr, int *num) { _GR_->SetMeshNum(*num); } -void mgl_set_alpha_default_(uintptr_t *gr, float *alpha) { _GR_->SetAlphaDef(*alpha); } +void mgl_set_alpha_default_(uintptr_t *gr, mreal *alpha) { _GR_->SetAlphaDef(*alpha); } void mgl_set_light_dif_(uintptr_t *gr, int *enable) { _GR_->SetDifLight(*enable); } //----------------------------------------------------------------------------- -void mgl_set_cut_box_(uintptr_t *gr, float *x1,float *y1,float *z1,float *x2,float *y2,float *z2) +void mgl_set_cut_box_(uintptr_t *gr, mreal *x1,mreal *y1,mreal *z1,mreal *x2,mreal *y2,mreal *z2) { _GR_->SetCutBox(*x1,*y1,*z1,*x2,*y2,*z2); } void mgl_set_cut_(uintptr_t *gr, int *cut) { _GR_->SetCut(*cut); } void mgl_set_cutoff_(uintptr_t *gr, const char *EqC, int l) @@ -107,19 +110,11 @@ void mgl_set_cutoff_(uintptr_t *gr, const char *EqC, int l) _GR_->CutOff(s); delete []s; } //----------------------------------------------------------------------------- void mgl_set_ternary_(uintptr_t *gr, int *enable) { _GR_->Ternary(*enable); } -void mgl_set_range_val_(uintptr_t *gr, const char *dir, float *v1,float *v2,int) -{ - if(*dir=='c') _GR_->CRange(*v1,*v2); - else if(*dir=='x') _GR_->XRange(*v1,*v2); - else if(*dir=='y') _GR_->YRange(*v1,*v2); - else if(*dir=='z') _GR_->ZRange(*v1,*v2); } +void mgl_set_range_val_(uintptr_t *gr, const char *dir, mreal *v1,mreal *v2,int) +{ mgl_set_range_val(_GR_,*dir,*v1,*v2); } void mgl_set_range_dat_(uintptr_t *gr, const char *dir, uintptr_t *a, int *add,int) -{ - if(*dir=='c') _GR_->CRange(*_DA_(a),*add); - else if(*dir=='x') _GR_->XRange(*_DA_(a),*add); - else if(*dir=='y') _GR_->YRange(*_DA_(a),*add); - else if(*dir=='z') _GR_->ZRange(*_DA_(a),*add); } -void mgl_set_ranges_(uintptr_t *gr, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2) +{ mgl_set_range_dat(_GR_,*dir,_DA_(a),*add); } +void mgl_set_ranges_(uintptr_t *gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2) { _GR_->SetRanges(*x1,*y1,*z1,*x2,*y2,*z2); } void mgl_set_func_(uintptr_t *gr, const char *EqX,const char *EqY,const char *EqZ,const char *EqA,int lx,int ly,int lz,int la) { @@ -143,20 +138,20 @@ void mgl_set_tick_rotate_(uintptr_t *gr,int *enable){ _GR_->SetTickRotate(*enabl void mgl_set_tick_skip_(uintptr_t *gr, int *enable) { _GR_->SetTickSkip(*enable); } //----------------------------------------------------------------------------- void mgl_set_rotated_text(HMGL gr, int enable) { gr->SetRotatedText(enable); } -void mgl_set_mark_size(HMGL gr, float size) { gr->SetMarkSize(size); } -void mgl_set_arrow_size(HMGL gr, float size) { gr->SetArrowSize(size); } -void mgl_set_font_size(HMGL gr, float size) { gr->SetFontSize(size); } +void mgl_set_mark_size(HMGL gr, mreal size) { gr->SetMarkSize(size); } +void mgl_set_arrow_size(HMGL gr, mreal size) { gr->SetArrowSize(size); } +void mgl_set_font_size(HMGL gr, mreal size) { gr->SetFontSize(size); } void mgl_set_font_def(HMGL gr, const char *fnt) { gr->SetFontDef(fnt); } void mgl_load_font(HMGL gr, const char *name, const char *path) { if(name && *name) gr->GetFont()->Load(name,path); else gr->GetFont()->Restore(); } void mgl_copy_font(HMGL gr, HMGL gr_from) { gr->GetFont()->Copy(gr_from->GetFont()); } void mgl_restore_font(HMGL gr) { gr->GetFont()->Restore(); } //----------------------------------------------------------------------------- -void mgl_set_bar_width_(uintptr_t *gr, float *width) { _GR_->SetBarWidth(*width); } +void mgl_set_bar_width_(uintptr_t *gr, mreal *width) { _GR_->SetBarWidth(*width); } void mgl_set_rotated_text_(uintptr_t *gr, int *rotated) { _GR_->SetRotatedText(*rotated); } -void mgl_set_mark_size_(uintptr_t *gr, float *size) { _GR_->SetMarkSize(*size); } -void mgl_set_arrow_size_(uintptr_t *gr, float *size) { _GR_->SetArrowSize(*size); } -void mgl_set_font_size_(uintptr_t *gr, float *size) { _GR_->SetFontSize(*size); } +void mgl_set_mark_size_(uintptr_t *gr, mreal *size) { _GR_->SetMarkSize(*size); } +void mgl_set_arrow_size_(uintptr_t *gr, mreal *size) { _GR_->SetArrowSize(*size); } +void mgl_set_font_size_(uintptr_t *gr, mreal *size) { _GR_->SetFontSize(*size); } void mgl_set_font_def_(uintptr_t *gr, char *name, int l) { char *s=new char[l+1]; memcpy(s,name,l); s[l]=0; _GR_->SetFontDef(s); delete []s; } @@ -190,14 +185,13 @@ void mgl_test_txt(const char *str, ...) fflush(stdout); } } -void mgl_set_test_mode(int enable) -{ mglTestMode=enable; } +void mgl_set_test_mode(int enable) { mglTestMode=enable; } //--------------------------------------------------------------------------- long mgl_use_graph(HMGL gr, int inc) -{ gr->InUse+=inc; return gr->InUse; } +{ if(!gr) return 0; gr->InUse+=inc; return gr->InUse; } long mgl_use_graph_(uintptr_t *gr, int *inc) -{ _GR_->InUse+=*inc; return _GR_->InUse; } +{ return mgl_use_graph(_GR_,*inc); } //--------------------------------------------------------------------------- -void mgl_set_ambbr(HMGL gr, float i) { gr->SetAmbient(i); } -void mgl_set_ambbr_(uintptr_t *gr, float *i){ _GR_->SetAmbient(*i); } +void mgl_set_ambbr(HMGL gr, mreal i) { gr->SetAmbient(i); } +void mgl_set_ambbr_(uintptr_t *gr, mreal *i){ _GR_->SetAmbient(*i); } //--------------------------------------------------------------------------- diff --git a/src/canvas.cpp b/src/canvas.cpp index ac931da..c37928d 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -17,8 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include +#include #include "mgl2/canvas.h" //----------------------------------------------------------------------------- mglCanvas::mglCanvas(int w, int h) : mglBase() @@ -66,7 +65,7 @@ void mglCanvas::GetDrwDat(long i) //----------------------------------------------------------------------------- const unsigned char *mglCanvas::GetBits() { Finish(); return G; } //----------------------------------------------------------------------------- -float mglCanvas::GetRatio() const { return inW/inH; } +mreal mglCanvas::GetRatio() const { return inW/inH; } //----------------------------------------------------------------------------- void mglCanvas::add_prim(mglPrim &a) { @@ -89,7 +88,8 @@ int Depth; ///< Depth of the image int CurFrameId; ///< Number of automaticle created frames GifFileType *gif;*/ SetTickRotate(true); SetTickSkip(true); - SetWarn(mglWarnNone); ObjId = -1; + SetWarn(mglWarnNone,""); + ObjId = -1; HighId = INT_MIN; SetFunc(0,0); Stop=false; CutOff(0); Ternary(0); SetRanges(mglPoint(-1,-1,-1,-1), mglPoint(1,1,1,1)); SetBarWidth(0.7); SetMarkSize(1); SetArrowSize(1); @@ -97,37 +97,39 @@ GifFileType *gif;*/ SetTranspType(0); SetMeshNum(0); // NOTE: default MeshNum=0 SetRotatedText(true); CurrPal = 0; SetLegendMarks(); SetFontSize(4); - SetTuneTicks(-1); SetAmbient(); + SetTuneTicks(-1); SetAmbient(); PlotId = "frame"; clr(MGL_DISABLE_SCALE); + clr(MGL_USE_GMTIME); clr(MGL_NOSUBTICKS); + SetDifLight(false); SetReduceAcc(false); SetDefScheme("BbcyrR"); SetPalette(MGL_DEF_PAL); - SetPenPal("k-1"); + SetPenPal("k-1"); Alpha(false); SetTicks('x'); SetTicks('y'); SetTicks('z'); SetTicks('c'); - stack.clear(); Restore(); Alpha(false); + stack.clear(); Restore(); DefColor('k'); + SetPlotFactor(0); InPlot(0,1,0,1,false); SetTickLen(0); SetCut(true); AdjustTicks("xyzc",true); Clf(); for(int i=0;i<10;i++) { AddLight(i, mglPoint(0,0,1)); Light(i,false); } Light(0,true); Light(false); SetDifLight(true); - SetPlotFactor(0); InPlot(0,1,0,1,false); } //----------------------------------------------------------------------------- // Optimal axis position //----------------------------------------------------------------------------- -float mglCanvas::FindOptOrg(char dir, int ind) const +mreal mglCanvas::FindOptOrg(char dir, int ind) const { static mglPoint px, py, pz, m1, m2; static mglMatrix bb; bb.b[0]=1e30; - mglPoint nn[8]={mglPoint(0,0,0), mglPoint(0,0,1), mglPoint(0,1,0), mglPoint(0,1,1), - mglPoint(1,0,0), mglPoint(1,0,1), mglPoint(1,1,0), mglPoint(1,1,1)}, pp[8]; + mglPoint nn[8]={mglPoint(0,0,0), mglPoint(0,0,1), mglPoint(0,1,0,0), mglPoint(0,1,1), + mglPoint(1,0,0), mglPoint(1,0,1), mglPoint(1,1,0), mglPoint(1,1,1)}, pp[8]; memcpy(pp, nn, 8*sizeof(mglPoint)); // do nothing if transformation matrix the same - if(memcmp(B.b,bb.b,9*sizeof(float)) || m1!=Min || m2!=Max) + if(memcmp(B.b,bb.b,9*sizeof(mreal)) || m1!=Min || m2!=Max) { m1 = Min; m2 = Max; memcpy(&bb,&B,sizeof(mglMatrix)); PostScale(pp,8); // find point with minimal y - register long i,j; - for(i=j=0;i<8;i++) if(pp[i].yHeight(font)*fsize, w; + if(ll==0) return 0; + + mreal fsize=size/6.5*font_factor, h = fnt->Height(font)*fsize, w, shift = -sh*h-2; // text drawing itself Push(); inv = inv ^ (strchr(font,'T')!=0); - if(inv) shift = sh+0.2; - shift += 0.11; // Correction for glyph rotation around proper point + if(inv) shift = 0.17*h-shift; + shift += 1.1; // Correction for glyph rotation around proper point +// shift *= h; - shift *= h; B.z= q.z; - if(ll==0) { Pop(); return 0; } + int align; mglGetStyle(font,0,&align); align = align&3; + B.x = q.x; B.y = q.y - shift; B.z = q.z; + if(ll>0) { B.x += shift*q.v/sqrt(ll); B.y += shift*(1-q.u/sqrt(ll)); } + fscl = fsize; - if(mgl_isnan(ll) || !get(MGL_ENABLE_RTEXT)) - { - fscl = fsize; ftet = 0; - B.x = q.x; B.y= q.y - shift; - } - else - { - if(ll==0) { Pop(); return 0; } - B.x = q.x+shift*q.v/sqrt(ll); - B.y= q.y-shift*q.u/sqrt(ll); - fscl = fsize; - ftet = -180*atan2(q.v,q.u)/M_PI; - } - memset(B.b,0,9*sizeof(float)); + if(mgl_isnan(ll) || !get(MGL_ENABLE_RTEXT)) ftet = 0; + else ftet = -180*atan2(q.v,q.u)/M_PI; + + memset(B.b,0,9*sizeof(mreal)); B.b[0] = B.b[4] = B.b[8] = fscl; - RotateN(ftet,0,0,1); + register mreal opf = B.pf; + RotateN(ftet,0,0,1); B.pf = opf; if(strchr(font,'@')) // draw box around text { long k1,k2,k3,k4; mglPnt pt; mglPoint pp; w = fnt->Width(text,font); h = fnt->Height(font); - int align; mglGetStyle(font,0,&align); align = align&3; - float d=-w*align/2.-h*0.2; w+=h*0.4; +// int align; mglGetStyle(font,0,&align); align = align&3; + mreal d=-w*align/2.-h*0.2; w+=h*0.4; pt = q; pp = mglPoint(d,-h*0.4); PostScale(pp); pt.x=pt.xx=pp.x; pt.y=pt.yy=pp.y; MGL_PUSH(Pnt,pt,mutexPnt); k1=Pnt.size()-1; pt = q; pp = mglPoint(w+d,-h*0.4); PostScale(pp); @@ -356,11 +354,11 @@ float mglCanvas::text_plot(long p,const wchar_t *text,const char *font,float siz Pop(); return fsize; } //----------------------------------------------------------------------------- -void mglCanvas::Glyph(float x, float y, float f, int s, long j, float col) +void mglCanvas::Glyph(mreal x, mreal y, mreal f, int s, long j, mreal col) { mglPrim a(4); // NOTE: no projection since text_plot() did it a.s = fscl/B.pf; a.w = ftet; a.p = B.pf; - float cc = col<0 ? AddTexture(char(0.5-col)):col; + mreal cc = col<0 ? AddTexture(char(0.5-col)):col; if(cc<0) cc = CDef; a.n1 = AddPnt(mglPoint(B.x,B.y,B.z), cc, mglPoint(x,y,f/fnt->GetFact(s&3)), -1, -1); a.n3 = s; a.n4 = j; @@ -372,11 +370,11 @@ void mglCanvas::Glyph(float x, float y, float f, int s, long j, float col) //----------------------------------------------------------------------------- // Plot positioning functions //----------------------------------------------------------------------------- -void mglCanvas::InPlot(float x1,float x2,float y1,float y2, const char *st) +void mglCanvas::InPlot(mreal x1,mreal x2,mreal y1,mreal y2, const char *st) { if(Width<=0 || Height<=0 || Depth<=0) return; if(!st) { InPlot(x1,x2,y1,y2,false); return; } - inW = Width*(x2-x1); inH = Height*(y2-y1); + inW = Width*(x2-x1); inH = Height*(y2-y1); ZMin=1; mglPrim p; p.id = ObjId; p.n1=x1*Width; p.n2=x2*Width; p.n3=y1*Height; p.n4=y2*Height; MGL_PUSH(Sub,p,mutexSub); @@ -387,7 +385,7 @@ void mglCanvas::InPlot(float x1,float x2,float y1,float y2, const char *st) bool u = !(strchr(st,'u') || strchr(st,'U') || strchr(st,'_') || strchr(st,'g')); bool a = !(strchr(st,'a') || strchr(st,'A') || strchr(st,'^') || strchr(st,'g') || strchr(st,'t')); // let use simplified scheme -- i.e. no differences between axis, colorbar and/or title - register float xs=(x1+x2)/2, ys=(y1+y2)/2, f1 = 1.3, f2 = 1.1; + register mreal xs=(x1+x2)/2, ys=(y1+y2)/2, f1 = 1.3, f2 = 1.1; if(r && l) { x2=xs+(x2-xs)*f1; x1=xs+(x1-xs)*f1; } else if(r) { x2=xs+(x2-xs)*f1; x1=xs+(x1-xs)*f2; } else if(l) { x2=xs+(x2-xs)*f2; x1=xs+(x1-xs)*f1; } @@ -405,7 +403,7 @@ void mglCanvas::InPlot(float x1,float x2,float y1,float y2, const char *st) B1=B; font_factor = B.b[0] < B.b[4] ? B.b[0] : B.b[4]; } //----------------------------------------------------------------------------- -void mglCanvas::InPlot(float x1,float x2,float y1,float y2, bool rel) +void mglCanvas::InPlot(mreal x1,mreal x2,mreal y1,mreal y2, bool rel) { if(Width<=0 || Height<=0 || Depth<=0) return; B.clear(); @@ -427,16 +425,16 @@ void mglCanvas::InPlot(float x1,float x2,float y1,float y2, bool rel) B.z = (1.f-B.b[8]/(2*Depth))*Depth; B1=B; } - inW = B.b[0]; inH=B.b[4]; + inW = B.b[0]; inH=B.b[4]; ZMin=1; font_factor = B.b[0] < B.b[4] ? B.b[0] : B.b[4]; mglPrim p; p.id = ObjId; p.n1=x1*Width; p.n2=x2*Width; p.n3=y1*Height; p.n4=y2*Height; MGL_PUSH(Sub,p,mutexSub); } //----------------------------------------------------------------------------- -void mglCanvas::StickPlot(int num, int id, float tet, float phi) +void mglCanvas::StickPlot(int num, int id, mreal tet, mreal phi) { - float dx,dy,wx,wy,x1,y1,f1,f2; + mreal dx,dy,wx,wy,x1,y1,f1,f2; mglPoint p1(-1,0,0), p2(1,0,0); // first iteration InPlot(0,1,0,1,true); Rotate(tet, phi); @@ -455,17 +453,17 @@ void mglCanvas::StickPlot(int num, int id, float tet, float phi) InPlot(x1*wx,(x1+1)*wx,y1*wy,(y1+1)*wy,true); Rotate(tet,phi); } //----------------------------------------------------------------------------- -void mglCanvas::Rotate(float tetz,float tetx,float tety) +void mglCanvas::Rotate(mreal tetz,mreal tetx,mreal tety) { // RotateN(TetX,1.,0.,0.); // RotateN(TetY,0.,1.,0.); // RotateN(TetZ,0.,0.,1.); - float R[9], O[9]; - float cx=cos(tetx*M_PI/180), sx=-sin(tetx*M_PI/180), cy=cos(tety*M_PI/180), sy=-sin(tety*M_PI/180), cz=cos(tetz*M_PI/180), sz=-sin(tetz*M_PI/180); + mreal R[9], O[9]; + mreal cx=cos(tetx*M_PI/180), sx=-sin(tetx*M_PI/180), cy=cos(tety*M_PI/180), sy=-sin(tety*M_PI/180), cz=cos(tetz*M_PI/180), sz=-sin(tetz*M_PI/180); R[0] = cx*cy; R[1] = -cy*sx; R[2] = sy; R[3] = cx*sy*sz+cz*sx; R[4] = cx*cz-sx*sy*sz; R[5] =-cy*sz; R[6] = sx*sz-cx*cz*sy; R[7] = cx*sz+cz*sx*sy; R[8] = cy*cz; - memcpy(O,B.b,9*sizeof(float)); + memcpy(O,B.b,9*sizeof(mreal)); B.b[0] = R[0]*O[0] + R[3]*O[1] + R[6]*O[2]; B.b[1] = R[1]*O[0] + R[4]*O[1] + R[7]*O[2]; B.b[2] = R[2]*O[0] + R[5]*O[1] + R[8]*O[2]; @@ -477,20 +475,20 @@ void mglCanvas::Rotate(float tetz,float tetx,float tety) B.b[8] = R[2]*O[6] + R[5]*O[7] + R[8]*O[8]; if(get(MGL_AUTO_FACTOR)) { - float w=(fabs(B.b[3])+fabs(B.b[4])+fabs(B.b[5]))/B1.b[4]; - float h=(fabs(B.b[0])+fabs(B.b[1])+fabs(B.b[2]))/B1.b[0]; + mreal w=(fabs(B.b[3])+fabs(B.b[4])+fabs(B.b[5]))/B1.b[4]; + mreal h=(fabs(B.b[0])+fabs(B.b[1])+fabs(B.b[2]))/B1.b[0]; B.pf = 1.55+0.6147*(w fabs(Ay) ? fabs(Ax) : fabs(Ay); + mreal a = fabs(Ax) > fabs(Ay) ? fabs(Ax) : fabs(Ay); a = a > fabs(Az) ? a : fabs(Az); if(a==0) { SetWarn(mglWarnZero,"Aspect"); return; } Ax/=a; Ay/=a; Az/=a; @@ -563,17 +561,17 @@ void mglCanvas::Aspect(float Ax,float Ay,float Az) //----------------------------------------------------------------------------- // Lighting and transparency //----------------------------------------------------------------------------- -void mglCanvas::Fog(float d, float dz) { FogDist=d; FogDz = dz; } +void mglCanvas::Fog(mreal d, mreal dz) { FogDist=d; FogDz = dz; } //----------------------------------------------------------------------------- void mglCanvas::Light(int n, bool enable) { - if(n<0 || n>9) { SetWarn(mglWarnLId); return; } + if(n<0 || n>9) { SetWarn(mglWarnLId,"Light"); return; } light[n].n = enable; } //----------------------------------------------------------------------------- -void mglCanvas::AddLight(int n, mglPoint r, mglPoint d, char col, float br, float ap) +void mglCanvas::AddLight(int n, mglPoint r, mglPoint d, char col, mreal br, mreal ap) { - if(n<0 || n>9) { SetWarn(mglWarnLId); return; } + if(n<0 || n>9) { SetWarn(mglWarnLId,"AddLight"); return; } light[n].n = true; light[n].a = ap>0?ap*ap:3; light[n].b = br; light[n].r = r; light[n].d = d; light[n].c = mglColor(col); @@ -586,11 +584,11 @@ void mglCanvas::arrow_plot(long n1, long n2,char st) mglPnt q1=p1,q2=p1,q3=p1,q4=p1; q1.u=q1.v=q2.u=q2.v=q3.u=q3.v=q4.u=q4.v=NAN; - float lx=p1.x-p2.x, ly=p1.y-p2.y, ll, kx,ky; + mreal lx=p1.x-p2.x, ly=p1.y-p2.y, ll, kx,ky; ll = hypot(lx,ly)/(PenWidth*ArrowSize*0.35*font_factor); if(ll==0) return; lx /= ll; ly /= ll; kx = ly; ky = -lx; - float lz = (p2.z-p1.z)/ll; + mreal lz = (p2.z-p1.z)/ll; Reserve(6); long k1,k2,k3,k4; @@ -658,10 +656,10 @@ void mglCanvas::arrow_plot(long n1, long n2,char st) } } //----------------------------------------------------------------------------- -void mglCanvas::Legend(const std::vector &leg, float x, float y, const char *font, float size, float ll) +void mglCanvas::Legend(const std::vector &leg, mreal x, mreal y, const char *font, mreal size, mreal ll) { long n=leg.size(), iw, ih; - if(n<1) { SetWarn(mglWarnLeg); return; } + if(n<1) { SetWarn(mglWarnLeg,"Legend"); return; } static int cgid=1; StartGroup("Legend",cgid++); if(ll<=0 || mgl_isnan(ll)) ll=0.1; ll *=font_factor; @@ -674,8 +672,8 @@ void mglCanvas::Legend(const std::vector &leg, float x, float y, const { *pA = ' '; InPlot(0,1,0,1,false); iw=B1.b[0]; ih=B1.b[4]; } else { iw=B1.b[0]/B1.pf; ih=B1.b[4]/B1.pf; } // find sizes - float h=TextHeight(font,size)/2; - float dx = 0.03*iw, dy = 0.03*ih, w=0, t; + mreal h=TextHeight(font,size)/2; + mreal dx = 0.03*iw, dy = 0.03*ih, w=0, t; register long i,j; for(i=0;i &leg, float x, float y, const w = w>t ? w:t; } w += ll+0.01*iw; // add space for lines - x = x*(iw-w-2*dx)+B.x-iw/2+dx; + x = x*(iw-w-2*dx)+B.x-iw/2+dx; // TODO bypass very long legends y = y*(ih-h*n-2*dy)+B.y-ih/2+dy; // draw it long k1=0,k2=0,k3=0,k4=0; @@ -699,8 +697,8 @@ void mglCanvas::Legend(const std::vector &leg, float x, float y, const } if(k4==2) k2=0; if(k4==1) k1=k2=0; - float c1=AddTexture(char(k1?k1:'w')), c2=AddTexture(char(k2?k2:'k')); - if((Flag&3)==2) { float cc=c1; c2=c1; c2=cc; }; + mreal c1=AddTexture(char(k1?k1:'w')), c2=AddTexture(char(k2?k2:'k')); + if((Flag&3)==2) { mreal cc=c1; c2=c1; c2=cc; }; if(strchr(ff,'#')) // draw bounding box { @@ -731,7 +729,7 @@ void mglCanvas::Legend(const std::vector &leg, float x, float y, const Pop(); EndGroup(); delete []ff; } //----------------------------------------------------------------------------- -void mglCanvas::Title(const char *title,const char *stl,float size) +void mglCanvas::Title(const char *title,const char *stl,mreal size) { wchar_t *wcs = 0; if(title) @@ -744,19 +742,19 @@ void mglCanvas::Title(const char *title,const char *stl,float size) if(wcs) delete []wcs; } //----------------------------------------------------------------------------- -void mglCanvas::Title(const wchar_t *title,const char *stl,float size) +void mglCanvas::Title(const wchar_t *title,const char *stl,mreal size) { - float s = size>0 ? size/FontSize:-size, h=TextHeight(stl,size)*s/4; + mreal s = size>0 ? size/FontSize:-size, h=TextHeight(stl,size)*s/4; if(h>=inH) { SetWarn(mglWarnSpc,"Title"); return; } bool box=(stl && strchr(stl,'#')); int align; mglGetStyle(stl,0,&align); align = align&3; - float x=B1.x-inW/2, y=B1.y+inH/2-h; + mreal x=B1.x-inW/2, y=B1.y+inH/2-h; mglPoint p(B1.x + inW/2.1*(align-1),y,Depth),q(NAN); if(title) text_plot(AddPnt(p,-1,q,-1,0),title,stl,size); if(box) // draw boungind box { - float c1=AddTexture('w'), c2=AddTexture('k'); - if((Flag&3)==2) { float cc=c1; c2=c1; c2=cc; }; + mreal c1=AddTexture('w'), c2=AddTexture('k'); + if((Flag&3)==2) { mreal cc=c1; c2=c1; c2=cc; }; long k1,k2,k3,k4; k1=AddPnt(mglPoint(x,y,Depth),c1,q,-1,0); k2=AddPnt(mglPoint(x+inW,y,Depth),c1,q,-1,0); diff --git a/src/canvas_cf.cpp b/src/canvas_cf.cpp index dc9044c..73b547c 100644 --- a/src/canvas_cf.cpp +++ b/src/canvas_cf.cpp @@ -28,9 +28,9 @@ const unsigned char *mgl_get_rgb(HMGL gr) { return _Gr_->GetBits(); } const unsigned char *mgl_get_rgba(HMGL gr) { return _Gr_->GetRGBA(); } int mgl_get_width(HMGL gr) { return _Gr_->GetWidth(); } int mgl_get_height(HMGL gr) { return _Gr_->GetHeight(); } -void mgl_calc_xyz(HMGL gr, int xs, int ys, float *x, float *y, float *z) +void mgl_calc_xyz(HMGL gr, int xs, int ys, mreal *x, mreal *y, mreal *z) { mglPoint p = _Gr_->CalcXYZ(xs,ys); *x = p.x; *y = p.y; *z = p.z; } -void mgl_calc_scr(HMGL gr, float x, float y, float z, int *xs, int *ys) +void mgl_calc_scr(HMGL gr, mreal x, mreal y, mreal z, int *xs, int *ys) { _Gr_->CalcScr(mglPoint(x,y,z),xs,ys); } void mgl_set_obj_id(HMGL gr, int id) { _Gr_->SetObjId(id); } int mgl_get_obj_id(HMGL gr, long x, long y) { return _Gr_->GetObjId(x,y); } @@ -43,24 +43,24 @@ void mgl_reset_frames(HMGL gr) { _Gr_->ResetFrames(); } //----------------------------------------------------------------------------- void mgl_set_transp_type(HMGL gr, int type) { _Gr_->SetTranspType(type); } void mgl_set_alpha(HMGL gr, int enable) { _Gr_->Alpha(enable); } -void mgl_set_fog(HMGL gr, float d, float dz) { _Gr_->Fog(d,dz); } +void mgl_set_fog(HMGL gr, mreal d, mreal dz) { _Gr_->Fog(d,dz); } void mgl_set_light(HMGL gr, int enable) { _Gr_->Light(enable); } void mgl_set_light_n(HMGL gr, int n, int enable) { _Gr_->Light(n, enable); } -void mgl_add_light_ext(HMGL gr, int n, float x, float y, float z, char c, float br, float ap) +void mgl_add_light_ext(HMGL gr, int n, mreal x, mreal y, mreal z, char c, mreal br, mreal ap) { _Gr_->AddLight(n,mglPoint(x,y,z),c,br,ap); } -void mgl_add_light_loc(HMGL gr, int n, float x, float y, float z, float dx, float dy, float dz, char c, float br, float ap) +void mgl_add_light_loc(HMGL gr, int n, mreal x, mreal y, mreal z, mreal dx, mreal dy, mreal dz, char c, mreal br, mreal ap) { _Gr_->AddLight(n,mglPoint(x,y,z),mglPoint(dx,dy,dz),c,br,ap); } -void mgl_add_light(HMGL gr, int n, float x, float y, float z) +void mgl_add_light(HMGL gr, int n, mreal x, mreal y, mreal z) { _Gr_->AddLight(n,mglPoint(x,y,z)); } //----------------------------------------------------------------------------- void mgl_mat_push(HMGL gr) { _Gr_->Push(); } void mgl_mat_pop(HMGL gr) { _Gr_->Pop(); } void mgl_clf(HMGL gr) { _Gr_->Clf(); } -void mgl_clf_rgb(HMGL gr, float r, float g, float b){ _Gr_->Clf(mglColor(r,g,b)); } +void mgl_clf_rgb(HMGL gr, mreal r, mreal g, mreal b){ _Gr_->Clf(mglColor(r,g,b)); } //----------------------------------------------------------------------------- -void mgl_subplot_d(HMGL gr, int nx,int ny,int m,const char *style,float dx,float dy) +void mgl_subplot_d(HMGL gr, int nx,int ny,int m,const char *style,mreal dx,mreal dy) { - float x1,x2,y1,y2; + mreal x1,x2,y1,y2; int mx = m%nx, my = m/nx; if(_Gr_->get(MGL_AUTO_FACTOR)) { dx /= 1.55; dy /= 1.55; } else { dx /= 2; dy /= 2; } @@ -74,51 +74,51 @@ void mgl_subplot(HMGL gr, int nx,int ny,int m,const char *style) //----------------------------------------------------------------------------- void mgl_multiplot(HMGL gr, int nx,int ny,int m,int dx,int dy,const char *style) { - float x1,x2,y1,y2; + mreal x1,x2,y1,y2; int mx = m%nx, my = m/nx; dx = (dx<1 || dx+mx>nx) ? 1 : dx; dy = (dy<1 || dy+my>ny) ? 1 : dy; - x1 = float(mx)/nx; x2 = float(mx+dx)/nx; - y2 = 1-float(my)/ny; y1 = 1-float(my+dy)/ny; + x1 = mreal(mx)/nx; x2 = mreal(mx+dx)/nx; + y2 = 1-mreal(my)/ny; y1 = 1-mreal(my+dy)/ny; _Gr_->InPlot(x1,x2,y1,y2,style); } //----------------------------------------------------------------------------- -void mgl_inplot(HMGL gr, float x1,float x2,float y1,float y2) +void mgl_inplot(HMGL gr, mreal x1,mreal x2,mreal y1,mreal y2) { _Gr_->InPlot(x1,x2,y1,y2,false); } -void mgl_relplot(HMGL gr, float x1,float x2,float y1,float y2) +void mgl_relplot(HMGL gr, mreal x1,mreal x2,mreal y1,mreal y2) { _Gr_->InPlot(x1,x2,y1,y2,true); } //----------------------------------------------------------------------------- -void mgl_columnplot(HMGL gr, int num, int i, float dd) +void mgl_columnplot(HMGL gr, int num, int i, mreal dd) { - register float w = 1./num; + register mreal w = 1./num; _Gr_->InPlot(0,1,1-w*(i+1-dd),1-i*w,true); } //----------------------------------------------------------------------------- -void mgl_gridplot(HMGL gr, int nx, int ny, int i, float dd) +void mgl_gridplot(HMGL gr, int nx, int ny, int i, mreal dd) { register int ix=i%nx, iy=i/nx; - register float wx = 1./nx, wy = 1./ny; + register mreal wx = 1./nx, wy = 1./ny; _Gr_->InPlot(ix*wx,wx*(ix+1-dd),1-wy*(iy+1-dd),1-iy*wy,true); } //----------------------------------------------------------------------------- -void mgl_stickplot(HMGL gr, int num, int i, float tet, float phi) +void mgl_stickplot(HMGL gr, int num, int i, mreal tet, mreal phi) { _Gr_->StickPlot(num, i, tet, phi); } //----------------------------------------------------------------------------- -void mgl_aspect(HMGL gr, float Ax,float Ay,float Az) +void mgl_aspect(HMGL gr, mreal Ax,mreal Ay,mreal Az) { _Gr_->Aspect(Ax,Ay,Az); } -void mgl_rotate(HMGL gr, float TetX,float TetZ,float TetY) +void mgl_rotate(HMGL gr, mreal TetX,mreal TetZ,mreal TetY) { _Gr_->Rotate(TetX,TetZ,TetY); } -void mgl_view(HMGL gr, float TetX,float TetZ,float TetY) +void mgl_view(HMGL gr, mreal TetX,mreal TetZ,mreal TetY) { _Gr_->View(TetX,TetZ,TetY); } -void mgl_zoom(HMGL gr, float x1, float y1, float x2, float y2) +void mgl_zoom(HMGL gr, mreal x1, mreal y1, mreal x2, mreal y2) { _Gr_->Zoom(x1,y1,x2,y2); } -void mgl_rotate_vector(HMGL gr, float Tet,float x,float y,float z) +void mgl_rotate_vector(HMGL gr, mreal Tet,mreal x,mreal y,mreal z) { _Gr_->RotateN(Tet,x,y,z); } -void mgl_perspective(HMGL gr, float val) +void mgl_perspective(HMGL gr, mreal val) { _Gr_->Perspective(val); } -void mgl_title(HMGL gr, const char *title, const char *stl, float size) +void mgl_title(HMGL gr, const char *title, const char *stl, mreal size) { _Gr_->Title(title,stl,size); } -void mgl_titlew(HMGL gr, const wchar_t *title, const char *stl, float size) +void mgl_titlew(HMGL gr, const wchar_t *title, const char *stl, mreal size) { _Gr_->Title(title,stl,size); } //----------------------------------------------------------------------------- int mgl_new_frame_(uintptr_t *gr) { return _GR_->NewFrame(); } @@ -128,25 +128,25 @@ void mgl_reset_frames_(uintptr_t *gr) { _GR_->ResetFrames(); } //----------------------------------------------------------------------------- void mgl_set_transp_type_(uintptr_t *gr, int *type) { _GR_->SetTranspType(*type); } void mgl_set_alpha_(uintptr_t *gr, int *enable) { _GR_->Alpha(*enable); } -void mgl_set_fog_(uintptr_t *gr, float *d, float *dz) { _GR_->Fog(*d, *dz); } +void mgl_set_fog_(uintptr_t *gr, mreal *d, mreal *dz) { _GR_->Fog(*d, *dz); } void mgl_set_light_(uintptr_t *gr, int *enable) { _GR_->Light(*enable); } void mgl_set_light_n_(uintptr_t *gr, int *n, int *enable) { _GR_->Light(*n, *enable); } -void mgl_add_light_(uintptr_t *gr, int *n, float *x, float *y, float *z) +void mgl_add_light_(uintptr_t *gr, int *n, mreal *x, mreal *y, mreal *z) { _GR_->AddLight(*n,mglPoint(*x,*y,*z)); } -void mgl_add_light_ext_(uintptr_t *gr, int *n, float *x, float *y, float *z, char *c, float *br, float *ap, int) +void mgl_add_light_ext_(uintptr_t *gr, int *n, mreal *x, mreal *y, mreal *z, char *c, mreal *br, mreal *ap, int) { _GR_->AddLight(*n,mglPoint(*x,*y,*z),*c,*br,*ap); } -void mgl_add_light_loc_(uintptr_t *gr, int *n, float *x, float *y, float *z, float *dx, float *dy, float *dz, char *c, float *br, float *ap, int) +void mgl_add_light_loc_(uintptr_t *gr, int *n, mreal *x, mreal *y, mreal *z, mreal *dx, mreal *dy, mreal *dz, char *c, mreal *br, mreal *ap, int) { _GR_->AddLight(*n,mglPoint(*x,*y,*z),mglPoint(*dx,*dy,*dz),*c,*br,*ap); } //----------------------------------------------------------------------------- void mgl_mat_push_(uintptr_t *gr) { _GR_->Push(); } void mgl_mat_pop_(uintptr_t *gr) { _GR_->Pop(); } void mgl_clf_(uintptr_t *gr) { _GR_->Clf(); } -void mgl_clf_rgb_(uintptr_t *gr, float *r, float *g, float *b) +void mgl_clf_rgb_(uintptr_t *gr, mreal *r, mreal *g, mreal *b) { _GR_->Clf(mglColor(*r,*g,*b)); } //----------------------------------------------------------------------------- -void mgl_subplot_d_(uintptr_t *gr, int *nx,int *ny,int *m,const char *st,float *dx,float *dy,int l) +void mgl_subplot_d_(uintptr_t *gr, int *nx,int *ny,int *m,const char *st,mreal *dx,mreal *dy,int l) { char *s=new char[l+1]; memcpy(s,st,l); s[l]=0; mgl_subplot_d(_GR_,*nx,*ny,*m,s,*dx,*dy); delete []s; } void mgl_subplot_(uintptr_t *gr, int *nx,int *ny,int *m,const char *st,int l) @@ -155,32 +155,32 @@ void mgl_subplot_(uintptr_t *gr, int *nx,int *ny,int *m,const char *st,int l) void mgl_multiplot_(uintptr_t *gr, int *nx,int *ny,int *m,int *dx,int *dy,const char *st,int l) { char *s=new char[l+1]; memcpy(s,st,l); s[l]=0; mgl_multiplot(_GR_,*nx,*ny,*m,*dx,*dy,s); delete []s; } -void mgl_inplot_(uintptr_t *gr, float *x1,float *x2,float *y1,float *y2) +void mgl_inplot_(uintptr_t *gr, mreal *x1,mreal *x2,mreal *y1,mreal *y2) { _GR_->InPlot(*x1,*x2,*y1,*y2,false); } -void mgl_relplot_(uintptr_t *gr, float *x1,float *x2,float *y1,float *y2) +void mgl_relplot_(uintptr_t *gr, mreal *x1,mreal *x2,mreal *y1,mreal *y2) { _GR_->InPlot(*x1,*x2,*y1,*y2,true); } -void mgl_columnplot_(uintptr_t *gr, int *num, int *i, float *d) +void mgl_columnplot_(uintptr_t *gr, int *num, int *i, mreal *d) { mgl_columnplot(_GR_,*num,*i,*d); } -void mgl_columnplot_d_(uintptr_t *gr, int *nx, int *ny, int *i, float *d) +void mgl_columnplot_d_(uintptr_t *gr, int *nx, int *ny, int *i, mreal *d) { mgl_gridplot(_GR_,*nx,*ny,*i,*d); } -void mgl_stickplot_(uintptr_t *gr, int *num, int *i, float *tet, float *phi) +void mgl_stickplot_(uintptr_t *gr, int *num, int *i, mreal *tet, mreal *phi) { _GR_->StickPlot(*num, *i, *tet, *phi); } -void mgl_title_(uintptr_t *gr, const char *title, const char *stl, float *size, int l,int m) +void mgl_title_(uintptr_t *gr, const char *title, const char *stl, mreal *size, int l,int m) { char *t=new char[l+1]; memcpy(t,title,l); t[l]=0; char *s=new char[m+1]; memcpy(s,stl,m); s[m]=0; _GR_->Title(t,s,*size); delete []s; delete []t; } -void mgl_aspect_(uintptr_t *gr, float *Ax,float *Ay,float *Az) +void mgl_aspect_(uintptr_t *gr, mreal *Ax,mreal *Ay,mreal *Az) { _GR_->Aspect(*Ax,*Ay,*Az); } -void mgl_rotate_(uintptr_t *gr, float *TetX,float *TetZ,float *TetY) +void mgl_rotate_(uintptr_t *gr, mreal *TetX,mreal *TetZ,mreal *TetY) { _GR_->Rotate(*TetX,*TetZ,*TetY); } -void mgl_view_(uintptr_t *gr, float *TetX,float *TetZ,float *TetY) +void mgl_view_(uintptr_t *gr, mreal *TetX,mreal *TetZ,mreal *TetY) { _GR_->View(*TetX,*TetZ,*TetY); } -void mgl_zoom_(uintptr_t *gr, float *x1, float *y1, float *x2, float *y2) +void mgl_zoom_(uintptr_t *gr, mreal *x1, mreal *y1, mreal *x2, mreal *y2) { _GR_->Zoom(*x1,*y1,*x2,*y2); } -void mgl_rotate_vector_(uintptr_t *gr, float *Tet,float *x,float *y,float *z) +void mgl_rotate_vector_(uintptr_t *gr, mreal *Tet,mreal *x,mreal *y,mreal *z) { _GR_->RotateN(*Tet,*x,*y,*z); } -void mgl_perspective_(uintptr_t *gr, float val) +void mgl_perspective_(uintptr_t *gr, mreal val) { _GR_->Perspective(val); } //----------------------------------------------------------------------------- const unsigned char *mgl_get_rgb_(uintptr_t *gr) { return gr ? _GR_->GetBits():0; } @@ -197,7 +197,7 @@ int mgl_get_spl_id_(uintptr_t *gr, int *x, int *y) { return _GR_->GetSplId(*x,*y //----------------------------------------------------------------------------- HMGL mgl_create_graph(int width, int height) { return new mglCanvas(width,height); } -void mgl_delete_graph(HMGL gr) { delete gr; } +void mgl_delete_graph(HMGL gr) { if(gr) delete gr; } void mgl_set_size(HMGL gr, int width, int height) { _Gr_->SetSize(width, height); } void mgl_set_def_param(HMGL gr) { _Gr_->DefaultPlotParam(); } @@ -205,15 +205,15 @@ void mgl_combine_gr(HMGL gr, HMGL in) { const mglCanvas *gg = dynamic_cast(in); if(gg) _Gr_->Combine(gg); } //----------------------------------------------------------------------------- -void mgl_set_tick_len(HMGL gr, float len, float stt) +void mgl_set_tick_len(HMGL gr, mreal len, mreal stt) { _Gr_->SetTickLen(len,stt); } void mgl_set_axis_stl(HMGL gr, const char *stl, const char *tck, const char *sub) { _Gr_->SetAxisStl(stl,tck,sub); } -void mgl_tune_ticks(HMGL gr, int tune, float pos) +void mgl_tune_ticks(HMGL gr, int tune, mreal pos) { _Gr_->SetTuneTicks(tune,pos); } void mgl_adjust_ticks(HMGL gr, const char *dir) { _Gr_->AdjustTicks(dir,true); } -void mgl_set_ticks(HMGL gr, char dir, float d, int ns, float org) +void mgl_set_ticks(HMGL gr, char dir, mreal d, int ns, mreal org) { _Gr_->SetTicks(dir,d,ns,org); } void mgl_set_ticks_str(HMGL gr, char dir, const char *lbl, int add) { _Gr_->SetTicksVal(dir,lbl,add); } @@ -227,7 +227,7 @@ void mgl_set_tick_templ(HMGL gr, char dir, const char *templ) { _Gr_->SetTickTempl(dir,templ); } void mgl_set_tick_templw(HMGL gr, char dir, const wchar_t *templ) { _Gr_->SetTickTempl(dir,templ); } -void mgl_set_ticks_time(HMGL gr, char dir, float d, const char *t) +void mgl_set_ticks_time(HMGL gr, char dir, mreal d, const char *t) { _Gr_->SetTickTime(dir,d,t); } //----------------------------------------------------------------------------- void mgl_box(HMGL gr) { _Gr_->Box(); } @@ -239,18 +239,18 @@ void mgl_axis_grid(HMGL gr, const char *dir,const char *pen) { _Gr_->Grid(dir,pen); } void mgl_label(HMGL gr, char dir, const char *text) { _Gr_->Label(dir,text); } -void mgl_label_ext(HMGL gr, char dir, const char *text, float pos, float shift) +void mgl_label_ext(HMGL gr, char dir, const char *text, mreal pos, mreal shift) { _Gr_->Label(dir,text,pos,shift); } -void mgl_labelw_ext(HMGL gr, char dir, const wchar_t *text, float pos, float shift) +void mgl_labelw_ext(HMGL gr, char dir, const wchar_t *text, mreal pos, mreal shift) { _Gr_->Labelw(dir,text,pos,shift); } //----------------------------------------------------------------------------- void mgl_colorbar(HMGL gr, const char *sch) { _Gr_->Colorbar(sch); } -void mgl_colorbar_ext(HMGL gr, const char *sch, float x, float y, float w, float h) +void mgl_colorbar_ext(HMGL gr, const char *sch, mreal x, mreal y, mreal w, mreal h) { _Gr_->Colorbar(sch,x,y,w,h); } void mgl_colorbar_val(HMGL gr, HCDT dat, const char *sch) { _Gr_->Colorbar(dat,sch); } -void mgl_colorbar_val_ext(HMGL gr, HCDT dat, const char *sch,float x, float y, float w, float h) +void mgl_colorbar_val_ext(HMGL gr, HCDT dat, const char *sch,mreal x, mreal y, mreal w, mreal h) { _Gr_->Colorbar(dat,sch,x,y,w,h); } //----------------------------------------------------------------------------- void mgl_add_legend(HMGL gr, const char *text,const char *style) @@ -259,9 +259,9 @@ void mgl_add_legendw(HMGL gr, const wchar_t *text,const char *style) { _Gr_->AddLegend(text,style); } void mgl_clear_legend(HMGL gr) { _Gr_->ClearLegend(); } -void mgl_legend_pos(HMGL gr, float x, float y, const char *font, float size, float llen) +void mgl_legend_pos(HMGL gr, mreal x, mreal y, const char *font, mreal size, mreal llen) { _Gr_->Legend(x,y,font,size,llen); } -void mgl_legend(HMGL gr, int where, const char *font, float size, float llen) +void mgl_legend(HMGL gr, int where, const char *font, mreal size, mreal llen) { _Gr_->Legend(where,font,size,llen); } void mgl_set_legend_marks(HMGL gr, int num) { _Gr_->SetLegendMarks(num); } @@ -275,7 +275,7 @@ void mgl_set_def_param_(uintptr_t *gr) { _GR_->DefaultPlotParam(); } void mgl_combine_gr_(uintptr_t *gr, uintptr_t *in) { _GR_->Combine((mglCanvas *)in); } //----------------------------------------------------------------------------- -void mgl_set_tick_len_(uintptr_t *gr, float *len, float *stt) +void mgl_set_tick_len_(uintptr_t *gr, mreal *len, mreal *stt) { _GR_->SetTickLen(*len, *stt); } void mgl_set_axis_stl_(uintptr_t *gr, const char *stl, const char *tck, const char *sub, int l,int m,int n) { char *a=new char[l+1]; memcpy(a,stl,l); a[l]=0; @@ -285,7 +285,7 @@ void mgl_set_axis_stl_(uintptr_t *gr, const char *stl, const char *tck, const ch void mgl_adjust_ticks_(uintptr_t *gr, const char *dir, int l) { char *s=new char[l+1]; memcpy(s,dir,l); s[l]=0; _GR_->AdjustTicks(s); delete []s; } -void mgl_set_ticks_(uintptr_t *gr, char *dir, float *d, int *ns, float *org, int) +void mgl_set_ticks_(uintptr_t *gr, char *dir, mreal *d, int *ns, mreal *org, int) { _GR_->SetTicks(*dir, *d, *ns, *org); } void mgl_set_ticks_str_(uintptr_t *gr, const char *dir, const char *lbl, int *add,int,int l) { char *s=new char[l+1]; memcpy(s,lbl,l); s[l]=0; @@ -293,12 +293,12 @@ void mgl_set_ticks_str_(uintptr_t *gr, const char *dir, const char *lbl, int *ad void mgl_set_ticks_val_(uintptr_t *gr, const char *dir, uintptr_t *val, const char *lbl, int *add,int,int l) { char *s=new char[l+1]; memcpy(s,lbl,l); s[l]=0; _GR_->SetTicksVal(*dir,_DA_(val),s,*add); delete []s; } -void mgl_tune_ticks_(uintptr_t *gr, int *tune, float *fact_pos) +void mgl_tune_ticks_(uintptr_t *gr, int *tune, mreal *fact_pos) { _GR_->SetTuneTicks(*tune, *fact_pos); } void mgl_set_tick_templ_(uintptr_t *gr, const char *dir, const char *templ,int,int l) { char *s=new char[l+1]; memcpy(s,templ,l); s[l]=0; _GR_->SetTickTempl(*dir,s); delete []s; } -void mgl_set_ticks_time_(uintptr_t *gr, const char *dir, float *d, const char *t,int,int l) +void mgl_set_ticks_time_(uintptr_t *gr, const char *dir, mreal *d, const char *t,int,int l) { char *s=new char[l+1]; memcpy(s,t,l); s[l]=0; _GR_->SetTickTime(*dir,*d,s); delete []s; } //----------------------------------------------------------------------------- @@ -317,20 +317,20 @@ void mgl_axis_grid_(uintptr_t *gr, const char *dir,const char *pen,int l,int n) void mgl_label_(uintptr_t *gr, const char *dir, const char *text,int,int l) { char *s=new char[l+1]; memcpy(s,text,l); s[l]=0; _GR_->Label(*dir, s); delete []s; } -void mgl_label_ext_(uintptr_t *gr, const char *dir, const char *text, float *pos, float *shift,int,int l) +void mgl_label_ext_(uintptr_t *gr, const char *dir, const char *text, mreal *pos, mreal *shift,int,int l) { char *s=new char[l+1]; memcpy(s,text,l); s[l]=0; _GR_->Label(*dir, s, *pos, *shift); delete []s; } //----------------------------------------------------------------------------- void mgl_colorbar_(uintptr_t *gr, const char *sch,int l) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; _GR_->Colorbar(s); delete []s; } -void mgl_colorbar_ext_(uintptr_t *gr, const char *sch, float *x, float *y, float *w, float *h, int l) +void mgl_colorbar_ext_(uintptr_t *gr, const char *sch, mreal *x, mreal *y, mreal *w, mreal *h, int l) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; _GR_->Colorbar(s,*x,*y,*w,*h); delete []s; } void mgl_colorbar_val_(uintptr_t *gr, uintptr_t *dat, const char *sch,int l) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; _GR_->Colorbar(_DA_(dat), s); delete []s; } -void mgl_colorbar_val_ext_(uintptr_t *gr, uintptr_t *dat, const char *sch, float *x, float *y, float *w, float *h, int l) +void mgl_colorbar_val_ext_(uintptr_t *gr, uintptr_t *dat, const char *sch, mreal *x, mreal *y, mreal *w, mreal *h, int l) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; _GR_->Colorbar(_DA_(dat),s,*x,*y,*w,*h); delete []s; } //----------------------------------------------------------------------------- @@ -339,10 +339,10 @@ void mgl_add_legend_(uintptr_t *gr, const char *text,const char *style,int l,int char *f=new char[n+1]; memcpy(f,style,n); f[n]=0; _GR_->AddLegend(s,f); delete []s; delete []f; } void mgl_clear_legend_(uintptr_t *gr) { if(gr) _GR_->ClearLegend(); } -void mgl_legend_pos_(uintptr_t *gr, float *x, float *y, const char *font, float *size, float *llen,int l) +void mgl_legend_pos_(uintptr_t *gr, mreal *x, mreal *y, const char *font, mreal *size, mreal *llen,int l) { char *s=new char[l+1]; memcpy(s,font,l); s[l]=0; _GR_->Legend(*x, *y, s, *size,*llen); delete []s; } -void mgl_legend_(uintptr_t *gr, int *where, const char *font, float *size, float *llen,int l) +void mgl_legend_(uintptr_t *gr, int *where, const char *font, mreal *size, mreal *llen,int l) { char *s=new char[l+1]; memcpy(s,font,l); s[l]=0; _GR_->Legend(*where, s, *size,*llen); delete []s; } void mgl_set_legend_marks_(uintptr_t *gr, int *num) @@ -362,7 +362,7 @@ void mgl_mpi_send_(uintptr_t *gr, int *id) { mgl_mpi_send(_GR_, *id); } void mgl_mpi_recv_(uintptr_t *gr, int *id) { mgl_mpi_recv(_GR_, *id); } //----------------------------------------------------------------------------- void mgl_wnd_set_delay_(uintptr_t *gr, mreal *dt) { _GR_->SetDelay(*dt); } -void mgl_wnd_set_delay(HMGL gr, float dt) { _Gr_->SetDelay(dt); } +void mgl_wnd_set_delay(HMGL gr, mreal dt) { _Gr_->SetDelay(dt); } //----------------------------------------------------------------------------- HMEX mgl_create_expr(const char *expr) { return new mglFormula(expr); } void mgl_delete_expr(HMEX ex) { delete ex; } @@ -380,13 +380,23 @@ uintptr_t mgl_create_expr_(const char *expr, int l) uintptr_t res = uintptr_t(mgl_create_expr(s)); delete []s; return res; } void mgl_delete_expr_(uintptr_t *ex) { mgl_delete_expr((HMEX)ex); } -float mgl_eval_expr_(uintptr_t *ex, float *x, float *y,float *z) +mreal mgl_eval_expr_(uintptr_t *ex, mreal *x, mreal *y,mreal *z) { return mgl_expr_eval((HMEX) ex, *x,*y,*z); } -float mgl_diff_expr_(uintptr_t *ex, const char *dir, float *x, float *y,float *z, int) +mreal mgl_diff_expr_(uintptr_t *ex, const char *dir, mreal *x, mreal *y,mreal *z, int) { return mgl_expr_diff((HMEX) ex, *dir,*x,*y,*z); } //----------------------------------------------------------------------------- -void mgl_set_plotfactor(HMGL gr, float val) +void mgl_set_plotfactor(HMGL gr, mreal val) { _Gr_->SetPlotFactor(val); } -void mgl_set_plotfactor_(uintptr_t *gr, float *val) +void mgl_set_plotfactor_(uintptr_t *gr, mreal *val) { _GR_->SetPlotFactor(*val); } //----------------------------------------------------------------------------- +void mgl_set_tick_shift(HMGL gr, mreal sx, mreal sy, mreal sz, mreal sc) +{ _Gr_->SetTickShift(mglPoint(sx,sy,sz,sc)); } +void mgl_set_tick_shift_(uintptr_t *gr, mreal *sx, mreal *sy, mreal *sz, mreal *sc) +{ _GR_->SetTickShift(mglPoint(*sx,*sy,*sz,*sc)); } +//----------------------------------------------------------------------------- +#if !MGL_HAVE_PNG +void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf){} +void mgl_write_prc_(uintptr_t *graph, const char *fname,const char *descr, int *make_pdf,int lf,int ld){} +#endif +//----------------------------------------------------------------------------- diff --git a/src/cont.cpp b/src/cont.cpp index ad5e025..9185dde 100644 --- a/src/cont.cpp +++ b/src/cont.cpp @@ -17,7 +17,6 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include #include "mgl2/surf.h" #include "mgl2/cont.h" @@ -39,16 +38,16 @@ bool same_chain(long f,long i,long *nn) } } //----------------------------------------------------------------------------- -void mgl_string_curve(mglBase *gr,long f,long ,long *ff,long *nn,const wchar_t *text, const char *font, float size) +void mgl_string_curve(mglBase *gr,long f,long ,long *ff,long *nn,const wchar_t *text, const char *font, mreal size) { if(nn[f]==-1) return; // do nothing since there is no curve if(!font) font=""; int pos = strchr(font,'t') ? 1:-1, align; char cc=mglGetStyle(font,0,&align); align = align&3; - float c=cc ? -cc : gr->GetClrC(ff[f]); + mreal c=cc ? -cc : gr->GetClrC(ff[f]); long len = wcslen(text); char *fnt = new char[strlen(font)+3]; strcpy(fnt,font); - float *wdt=new float[len+1], h=gr->TextHeight(font,size)/4, tet, tt; // TODO optimaze ratio + mreal *wdt=new mreal[len+1], h=gr->TextHeight(font,size)/4, tet, tt; // TODO optimaze ratio mglPoint *pt=new mglPoint[len+1]; wchar_t L[2]=L"a"; register long i,j,k,m; @@ -85,7 +84,7 @@ void mgl_string_curve(mglBase *gr,long f,long ,long *ff,long *nn,const wchar_t * // place glyphs points pt[0] = qa[0]; m = qa.size(); - float a,b,d,w,t1,t2; + mreal a,b,d,w,t1,t2; for(i=j=0,tt=0;jStop) { delete []wdt; delete []pt; delete []fnt; return; } @@ -104,26 +103,28 @@ void mgl_string_curve(mglBase *gr,long f,long ,long *ff,long *nn,const wchar_t * if(rev) pos=-pos; for(j=0;jtext_plot(gr->AddPnt(pt[j]-(pos*h)*l,c,s,-1,-1),L,font,size,0,c); } + gr->text_plot(gr->AddPnt(pt[j]-(pos*h)*l,c,s,-1,-1),L,font,size,0.05,c); } delete []wdt; delete []pt; delete []fnt; } //----------------------------------------------------------------------------- void mgl_textw_xyz(HMGL gr, HCDT x, HCDT y, HCDT z,const wchar_t *text, const char *font, const char *opt) { long n=y->GetNx(); - if(x->GetNx()!=n || z->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Text"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Text"); return; } + if(mgl_check_dim1(gr,x,y,z,0,"Text")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("TextC",cgid++); long *nn = new long[n], *ff = new long[n]; mglPoint p; register long i; - for(i=0;iv(i),y->v(i),z->v(i)); - ff[i] = gr->AddPnt(p,-1); - } + const mglData *mdx = dynamic_cast(x); + const mglData *mdy = dynamic_cast(y); + const mglData *mdz = dynamic_cast(z); + if(mdx && mdy && mdz) for(i=0;ia[i],mdy->a[i],mdz->a[i]); ff[i] = gr->AddPnt(p,-1); } + else for(i=0;iv(i),y->v(i),z->v(i)); ff[i] = gr->AddPnt(p,-1); } for(i=1;iGetNx()<2) { gr->SetWarn(mglWarnLow,"Text"); return; } gr->SaveState(opt); mglData z(y->GetNx()); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_textw_xyz(gr,x,y,&z,text,font,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_textw_y(HMGL gr, HCDT y, const wchar_t *text, const char *font, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Text"); return; } gr->SaveState(opt); mglData x(y->GetNx()), z(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_textw_xyz(gr,&x,y,&z,text,font,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_text_xyz(HMGL gr, HCDT x, HCDT y, HCDT z,const char *text, const char *font, const char *opt) @@ -161,18 +162,16 @@ void mgl_text_xyz(HMGL gr, HCDT x, HCDT y, HCDT z,const char *text, const char * //----------------------------------------------------------------------------- void mgl_text_xy(HMGL gr, HCDT x, HCDT y, const char *text, const char *font, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Text"); return; } mglData z(y->GetNx()); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_text_xyz(gr,x,y,&z,text,font,opt); } //----------------------------------------------------------------------------- void mgl_text_y(HMGL gr, HCDT y, const char *text, const char *font, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Text"); return; } mglData x(y->GetNx()), z(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_text_xyz(gr,&x,y,&z,text,font,opt); } //----------------------------------------------------------------------------- @@ -207,7 +206,7 @@ struct mglSegment mglSegment(mglPoint q1,mglPoint q2) {p1=q1;p2=q2;next=prev=-1;} }; // function for connecting arbitrary line segments -/*void mgl_connect(HMGL gr, float val, HCDT a, HCDT x, HCDT y, HCDT z, float c, int text,long ak) +/*void mgl_connect(HMGL gr, mreal val, HCDT a, HCDT x, HCDT y, HCDT z, mreal c, int text,long ak) { long n=a->GetNx(), m=a->GetNy(); if(n<2 || m<2 || x->GetNx()*x->GetNy()!=n*m || y->GetNx()*y->GetNy()!=n*m || z->GetNx()*z->GetNy()!=n*m) @@ -215,7 +214,7 @@ struct mglSegment std::vector ss,cc; register long i,j; - float d1,d2,d3,d4; + mreal d1,d2,d3,d4; bool o1,o2,o3,o4; mglPoint p1,p2,p3,p4,q1,q2,q3,q4; for(i=0;i &kk) +struct mglPnt2 { mreal x,y; mglPnt2(mreal xx=0,mreal yy=0) {x=xx;y=yy;} }; +long *mgl_cont_prep(mreal val, HCDT a,long ak, std::vector &kk) { long n=a->GetNx(), m=a->GetNy(); - float d, r, kx, ky; + mreal d, r, kx, ky; register long i,j,k, pc=0; kk.clear(); // add intersection point of isoline and Y axis - for(i=0;i(a); + if(ma) { - d = mgl_d(val,a->v(i,j,ak),a->v(i+1,j,ak)); - if(d>=0 && d<1) kk.push_back(mglPnt2(i+d,j)); + for(i=0;ia[i+n*(j+m*ak)],ma->a[i+1+n*(j+m*ak)]); + if(d>=0 && d<1) kk.push_back(mglPnt2(i+d,j)); + } + // add intersection point of isoline and X axis + for(i=0;ia[i+n*(j+m*ak)],ma->a[i+n*(j+1+m*ak)]); + if(d>=0 && d<1) kk.push_back(mglPnt2(i,j+d)); + } } - // add intersection point of isoline and X axis - for(i=0;iv(i,j,ak),a->v(i,j+1,ak)); + register mreal vv = a->v(i,j,ak); + d = (iv(i+1,j,ak)):-1; + if(d>=0 && d<1) kk.push_back(mglPnt2(i+d,j)); + d = (jv(i,j+1,ak)):-1; if(d>=0 && d<1) kk.push_back(mglPnt2(i,j+d)); } @@ -321,7 +332,7 @@ long *mgl_cont_prep(float val, HCDT a,long ak, std::vector &kk) } //----------------------------------------------------------------------------- // NOTE! All data MUST have the same size! Only first slice is used! -void mgl_cont_gen(HMGL gr, float val, HCDT a, HCDT x, HCDT y, HCDT z, float c, int text,long ak) +void mgl_cont_gen(HMGL gr, mreal val, HCDT a, HCDT x, HCDT y, HCDT z, mreal c, int text,long ak) { long n=a->GetNx(), m=a->GetNy(); if(n<2 || m<2 || x->GetNx()*x->GetNy()!=n*m || y->GetNx()*y->GetNy()!=n*m || z->GetNx()*z->GetNy()!=n*m) @@ -331,7 +342,7 @@ void mgl_cont_gen(HMGL gr, float val, HCDT a, HCDT x, HCDT y, HCDT z, float c, i long *nn = mgl_cont_prep(val, a, ak, kk), *ff; if(!nn) return; // nothing to do register long i, pc=kk.size(); - register float xx, yy; + register mreal xx, yy; ff = new long[pc]; gr->Reserve(pc); for(i=0;iTextWidth(wcs,"",-0.5); + mreal del = 2*gr->TextWidth(wcs,"",-0.5); // find width and height of drawing area - float ar=gr->GetRatio(), w=gr->FontFactor(), h; + mreal ar=gr->GetRatio(), w=gr->FontFactor(), h; if(delSetPenPal(sch); @@ -383,10 +394,8 @@ void mgl_cont_gen(HMGL gr, float val, HCDT a, HCDT x, HCDT y, HCDT z, const char void mgl_cont_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Cont"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Cont"); return; } - bool both = x->GetNx()*x->GetNy()==m*n && y->GetNx()*y->GetNy()==m*n; - if(y->GetNx()!=z->GetNy() && !both) { gr->SetWarn(mglWarnDim, "Cont"); return; } + if(mgl_check_dim2(gr,x,y,z,0,"Cont")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Cont",cgid++); @@ -396,22 +405,25 @@ void mgl_cont_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, c gr->SetPenPal(sch); mglData xx, yy, zz(z->GetNx(), z->GetNy()); - if(!both) // make + if(x->GetNx()*x->GetNy()!=m*n || y->GetNx()*y->GetNy()!=m*n) // make { - xx.Create(z->GetNx(), z->GetNy()); - yy.Create(z->GetNx(), z->GetNy()); - for(i=0;i(x); + const mglData *my = dynamic_cast(y); + if(mx && my) for(i=0;ia[i]; yy.a[i+n*j] = my->a[j]; } + else for(i=0;iv(i); yy.a[i+n*j] = y->v(j); } x = &xx; y = &yy; } // x, y -- have the same size z - float z0, v0; + mreal z0, v0; for(j=0;jGetNz();j++) for(i=0;iGetNx();i++) { if(gr->Stop) return; v0 = v->v(i); z0 = fixed ? gr->Min.z : v0; if(z->GetNz()>1) - z0 = gr->Min.z+(gr->Max.z-gr->Min.z)*float(j)/(z->GetNz()-1); + z0 = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(j)/(z->GetNz()-1); zz.Fill(z0,z0); mgl_cont_gen(gr,v0,z,x,y,&zz,gr->GetC(s,v0),text,j); } @@ -420,32 +432,36 @@ void mgl_cont_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, c //----------------------------------------------------------------------------- void mgl_cont_val(HMGL gr, HCDT v, HCDT z, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2) { gr->SetWarn(mglWarnLow,"Cont"); return; } + register long n = z->GetNx(), m = z->GetNy(); + if(m<2 || n<2) { gr->SetWarn(mglWarnLow,"Cont"); return; } gr->SaveState(opt); - mglData x(z->GetNx(), z->GetNy()), y(z->GetNx(), z->GetNy()); + mglData x(n, m), y(n, m); x.Fill(gr->Min.x,gr->Max.x,'x'); y.Fill(gr->Min.y,gr->Max.y,'y'); mgl_cont_xy_val(gr,v,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_cont_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); gr->LoadState(); return; } mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); mgl_cont_xy_val(gr,&v,x,y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_cont(HMGL gr, HCDT z, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); gr->LoadState(); return; } mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); mgl_cont_val(gr,&v,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_cont_xy_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -473,7 +489,7 @@ mgl_cont(_GR_, _DA_(a), s, o); delete []o; delete []s; } // ContF series // //----------------------------------------------------------------------------- -long mgl_add_pnt(HMGL gr, float d, HCDT x, HCDT y, HCDT z, long i1, long j1, long i2, long j2, float c, bool edge) +long mgl_add_pnt(HMGL gr, mreal d, HCDT x, HCDT y, HCDT z, long i1, long j1, long i2, long j2, mreal c, bool edge) { long res=-1; if(edge || (d>0 && d<1)) @@ -493,11 +509,11 @@ long mgl_add_pnt(HMGL gr, float d, HCDT x, HCDT y, HCDT z, long i1, long j1, lon return res; } //----------------------------------------------------------------------------- -void mgl_add_range(HMGL gr, HCDT a, HCDT x, HCDT y, HCDT z, long i1, long j1, long di, long dj, float c, long &u1, long &u2, long ak, float v1, float v2) +void mgl_add_range(HMGL gr, HCDT a, HCDT x, HCDT y, HCDT z, long i1, long j1, long di, long dj, mreal c, long &u1, long &u2, long ak, mreal v1, mreal v2) { long i2=i1+di, j2=j1+dj; - float f1 = a->v(i1,j1,ak), f2 = a->v(i2,j2,ak), d1, d2; + mreal f1 = a->v(i1,j1,ak), f2 = a->v(i2,j2,ak), d1, d2; d1 = mgl_d(v1,f1,f2); u1 = mgl_add_pnt(gr,d1,x,y,z,i1,j1,i2,j2,c,false); d2 = mgl_d(v2,f1,f2); @@ -505,19 +521,19 @@ void mgl_add_range(HMGL gr, HCDT a, HCDT x, HCDT y, HCDT z, long i1, long j1, lo if(d1>d2) { j2=u1; u1=u2; u2=j2; } } //----------------------------------------------------------------------------- -void mgl_add_edges(HMGL gr, HCDT a, HCDT x, HCDT y, HCDT z, long i1, long j1, long di, long dj, float c, long &u1, long &u2, long ak, float v1, float v2) +void mgl_add_edges(HMGL gr, HCDT a, HCDT x, HCDT y, HCDT z, long i1, long j1, long di, long dj, mreal c, long &u1, long &u2, long ak, mreal v1, mreal v2) { long i2=i1+di, j2=j1+dj; u1 = u2 = -1; - float f1 = a->v(i1,j1,ak), f2 = a->v(i2,j2,ak); + mreal f1 = a->v(i1,j1,ak), f2 = a->v(i2,j2,ak); if(f1<=v2 && f1>=v1) u1 = mgl_add_pnt(gr,0,x,y,z,i1,j1,i2,j2,c,true); if(f2<=v2 && f2>=v1) u2 = mgl_add_pnt(gr,1,x,y,z,i1,j1,i2,j2,c,true); } //----------------------------------------------------------------------------- -void mgl_contf_gen(HMGL gr, float v1, float v2, HCDT a, HCDT x, HCDT y, HCDT z, float c, long ak) +void mgl_contf_gen(HMGL gr, mreal v1, mreal v2, HCDT a, HCDT x, HCDT y, HCDT z, mreal c, long ak) { long n=a->GetNx(), m=a->GetNy(); if(n<2 || m<2 || x->GetNx()*x->GetNy()!=n*m || y->GetNx()*y->GetNy()!=n*m || z->GetNx()*z->GetNy()!=n*m) @@ -577,7 +593,7 @@ void mgl_contf_gen(HMGL gr, float v1, float v2, HCDT a, HCDT x, HCDT y, HCDT z, delete []kk; } //----------------------------------------------------------------------------- -void mgl_contf_gen(HMGL gr, float v1, float v2, HCDT a, HCDT x, HCDT y, HCDT z, const char *c) +void mgl_contf_gen(HMGL gr, mreal v1, mreal v2, HCDT a, HCDT x, HCDT y, HCDT z, const char *c) { gr->SetPenPal(c); mgl_contf_gen(gr,v1,v2,a,x,y,z,gr->CDef,0); @@ -586,32 +602,33 @@ void mgl_contf_gen(HMGL gr, float v1, float v2, HCDT a, HCDT x, HCDT y, HCDT z, void mgl_contf_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"ContF"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContF"); return; } - bool both = x->GetNx()*x->GetNy()==m*n && y->GetNx()*y->GetNy()==m*n; - if(y->GetNx()!=z->GetNy() && !both) { gr->SetWarn(mglWarnDim, "ContF"); return; } + if(mgl_check_dim2(gr,x,y,z,0,"ContF")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("ContF",cgid++); long s=gr->AddTexture(sch); bool fixed=(sch && strchr(sch,'_')) || (gr->Min.z==gr->Max.z); - mglData xx, yy, zz(z->GetNx(), z->GetNy()); - if(!both) // make + mglData xx, yy, zz(n, m); + if(x->GetNx()*x->GetNy()!=m*n || y->GetNx()*y->GetNy()!=m*n) // make { - xx.Create(z->GetNx(), z->GetNy()); - yy.Create(z->GetNx(), z->GetNy()); - for(j=0;j(x); + const mglData *my = dynamic_cast(y); + if(mx && my) for(i=0;ia[i]; yy.a[i+n*j] = my->a[j]; } + else for(i=0;iv(i); yy.a[i+n*j] = y->v(j); } x = &xx; y = &yy; } // x, y -- have the same size z - float z0, v0; + mreal z0, v0; for(j=0;jGetNz();j++) for(i=0;iGetNx()-1;i++) { if(gr->Stop) return; v0 = v->v(i); z0 = fixed ? gr->Min.z : v0; if(z->GetNz()>1) - z0 = gr->Min.z+(gr->Max.z-gr->Min.z)*float(j)/(z->GetNz()-1); + z0 = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(j)/(z->GetNz()-1); zz.Fill(z0,z0); mgl_contf_gen(gr,v0,v->v(i+1),z,x,y,&zz,gr->GetC(s,v0),j); } @@ -620,30 +637,34 @@ void mgl_contf_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, //----------------------------------------------------------------------------- void mgl_contf_val(HMGL gr, HCDT v, HCDT z, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2) { gr->SetWarn(mglWarnLow,"Cont"); return; } + register long n = z->GetNx(), m = z->GetNy(); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Cont"); return; } gr->SaveState(opt); - mglData x(z->GetNx(), z->GetNy()), y(z->GetNx(), z->GetNy()); + mglData x(n, m), y(n, m); x.Fill(gr->Min.x,gr->Max.x,'x'); y.Fill(gr->Min.y,gr->Max.y,'y'); mgl_contf_xy_val(gr,v,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contf_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); gr->LoadState(); return; } mglData v(Num+2); v.Fill(gr->Min.c, gr->Max.c); mgl_contf_xy_val(gr,&v,x,y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contf(HMGL gr, HCDT z, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); gr->LoadState(); return; } mglData v(Num+2); v.Fill(gr->Min.c, gr->Max.c); mgl_contf_val(gr,&v,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contf_xy_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -683,10 +704,8 @@ int mgl_get_ncol(const char *sch, char *res) void mgl_contd_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j=0,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"ContD"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContD"); return; } - bool both = x->GetNx()*x->GetNy()==m*n && y->GetNx()*y->GetNy()==m*n; - if(y->GetNx()!=z->GetNy() && !both) { gr->SetWarn(mglWarnDim, "ContD"); return; } + if(mgl_check_dim2(gr,x,y,z,0,"ContD")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("ContD",cgid++); @@ -695,23 +714,26 @@ void mgl_contd_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, if(j==0) sch = MGL_DEF_PAL; long s = gr->AddTexture(sch,1); int nc = gr->GetNumPal(s*256); - mglData xx, yy, zz(z->GetNx(), z->GetNy()); - if(!both) // make + mglData xx, yy, zz(n, m); + if(x->GetNx()*x->GetNy()!=m*n || y->GetNx()*y->GetNy()!=m*n) // make { - xx.Create(z->GetNx(), z->GetNy()); - yy.Create(z->GetNx(), z->GetNy()); - for(i=0;i(x); + const mglData *my = dynamic_cast(y); + if(mx && my) for(i=0;ia[i]; yy.a[i+n*j] = my->a[j]; } + else for(i=0;iv(i); yy.a[i+n*j] = y->v(j); } x = &xx; y = &yy; } // x, y -- have the same size z - float z0, v0, dc = nc>1 ? 1/(MGL_FLT_EPS*(nc-1)) : 0; + mreal z0, v0, dc = nc>1 ? 1/(MGL_EPSILON*(nc-1)) : 0; for(j=0;jGetNz();j++) for(i=0;iGetNx()-1;i++) { if(gr->Stop) return; v0 = v->v(i); z0 = fixed ? gr->Min.z : v0; if(z->GetNz()>1) - z0 = gr->Min.z+(gr->Max.z-gr->Min.z)*float(j)/(z->GetNz()-1); + z0 = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(j)/(z->GetNz()-1); zz.Fill(z0,z0); mgl_contf_gen(gr,v0,v->v(i+1),z,x,y,&zz,s+i*dc,j); } @@ -720,12 +742,14 @@ void mgl_contd_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, //----------------------------------------------------------------------------- void mgl_contd_val(HMGL gr, HCDT v, HCDT z, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2) { gr->SetWarn(mglWarnLow,"ContD"); return; } + register long n = z->GetNx(), m = z->GetNy(); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContD"); return; } gr->SaveState(opt); - mglData x(z->GetNx(), z->GetNy()), y(z->GetNx(), z->GetNy()); + mglData x(n, m), y(n, m); x.Fill(gr->Min.x,gr->Max.x,'x'); y.Fill(gr->Min.y,gr->Max.y,'y'); mgl_contd_xy_val(gr,v,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contd_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) @@ -734,6 +758,7 @@ void mgl_contd_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char * mglData v(mgl_get_ncol(sch,0)+1); v.Fill(gr->Min.c, gr->Max.c); mgl_contd_xy_val(gr,&v,x,y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contd(HMGL gr, HCDT z, const char *sch, const char *opt) @@ -742,6 +767,7 @@ void mgl_contd(HMGL gr, HCDT z, const char *sch, const char *opt) mglData v(mgl_get_ncol(sch,0)+1); v.Fill(gr->Min.c, gr->Max.c); mgl_contd_val(gr,&v,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contd_xy_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -770,7 +796,7 @@ void mgl_contd_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,in // //----------------------------------------------------------------------------- // NOTE! All data MUST have the same size! Only first slice is used! -void mgl_contv_gen(HMGL gr, float val, float dval, HCDT a, HCDT x, HCDT y, HCDT z, float c, long ak) +void mgl_contv_gen(HMGL gr, mreal val, mreal dval, HCDT a, HCDT x, HCDT y, HCDT z, mreal c, long ak) { long n=a->GetNx(), m=a->GetNy(); if(n<2 || m<2 || x->GetNx()*x->GetNy()!=n*m || y->GetNx()*y->GetNy()!=n*m || z->GetNx()*z->GetNy()!=n*m) @@ -780,7 +806,7 @@ void mgl_contv_gen(HMGL gr, float val, float dval, HCDT a, HCDT x, HCDT y, HCDT long *nn = mgl_cont_prep(val, a, ak, kk), *ff; if(!nn) return; // nothing to do register long i, pc=kk.size(); - register float xx, yy; + register mreal xx, yy; ff = new long[2*pc]; gr->Reserve(2*pc); mglPoint p,q; for(i=0;iGetNx(),m=z->GetNy(); - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Cont"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Cont"); return; } - bool both = x->GetNx()*x->GetNy()==m*n && y->GetNx()*y->GetNy()==m*n; - if(y->GetNx()!=z->GetNy() && !both) { gr->SetWarn(mglWarnDim, "Cont"); return; } - gr->SaveState(opt); - static int cgid=1; gr->StartGroup("Cont",cgid++); + if(mgl_check_dim2(gr,x,y,z,0,"ContV")) return; + gr->SaveState(opt); + static int cgid=1; gr->StartGroup("ContV",cgid++); bool fixed=(sch && strchr(sch,'_')) || (gr->Min.z==gr->Max.z); long s=gr->AddTexture(sch); gr->SetPenPal(sch); - mglData xx, yy, zz(z->GetNx(), z->GetNy()); - if(!both) // make + mglData xx, yy, zz(n, m); + if(x->GetNx()*x->GetNy()!=m*n || y->GetNx()*y->GetNy()!=m*n) // make { - xx.Create(z->GetNx(), z->GetNy()); - yy.Create(z->GetNx(), z->GetNy()); - for(i=0;i(x); + const mglData *my = dynamic_cast(y); + if(mx && my) for(i=0;ia[i]; yy.a[i+n*j] = my->a[j]; } + else for(i=0;iv(i); yy.a[i+n*j] = y->v(j); } x = &xx; y = &yy; } // x, y -- have the same size z - float z0, v0; + mreal z0, v0; for(j=0;jGetNz();j++) for(i=0;iGetNx();i++) { if(gr->Stop) return; v0 = v->v(i); z0 = fixed ? gr->Min.z : v0; - if(z->GetNz()>1) z0 = gr->Min.z+(gr->Max.z-gr->Min.z)*float(j)/(z->GetNz()-1); + if(z->GetNz()>1) z0 = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(j)/(z->GetNz()-1); zz.Fill(z0,z0); - float dv = (gr->Max.c-gr->Min.c)/8; + mreal dv = (gr->Max.c-gr->Min.c)/8; if(i>0) dv = v->v(i-1)-v->v(i); else if(iGetNx()-1) dv = v->v(i)-v->v(i+1); if(fixed) dv=-dv; @@ -837,32 +863,36 @@ void mgl_contv_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, //----------------------------------------------------------------------------- void mgl_contv_val(HMGL gr, HCDT v, HCDT z, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2) { gr->SetWarn(mglWarnLow,"Cont"); return; } + register long n = z->GetNx(), m = z->GetNy(); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Cont"); return; } gr->SaveState(opt); - mglData x(z->GetNx(), z->GetNy()), y(z->GetNx(), z->GetNy()); + mglData x(n, m), y(n, m); x.Fill(gr->Min.x,gr->Max.x,'x'); y.Fill(gr->Min.y,gr->Max.y,'y'); mgl_contv_xy_val(gr,v,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contv_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); gr->LoadState(); return; } mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); mgl_contv_xy_val(gr,&v,x,y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contv(HMGL gr, HCDT z, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont"); gr->LoadState(); return; } mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); mgl_contv_val(gr,&v,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_contv_xy_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -892,7 +922,7 @@ void mgl_contv_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,in //----------------------------------------------------------------------------- struct _mgl_slice { mglData x,y,z,a; }; //----------------------------------------------------------------------------- -void mgl_get_slice(_mgl_slice &s, HCDT x, HCDT y, HCDT z, HCDT a, char dir, float d, bool both) +void mgl_get_slice(_mgl_slice &s, HCDT x, HCDT y, HCDT z, HCDT a, char dir, mreal d, bool both) { register long i,j,i0,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(), nx=1,ny=1,p; @@ -905,7 +935,7 @@ void mgl_get_slice(_mgl_slice &s, HCDT x, HCDT y, HCDT z, HCDT a, char dir, floa if(dir=='x' && p>=n-1) { d+=p-n+2; p=n-2; } if(dir=='y' && p>=m-1) { d+=p-m+2.; p=m-2; } if(dir=='z' && p>=l-1) { d+=p-l+2; p=l-2; } - float v; + mreal v; if(both) { @@ -969,13 +999,88 @@ void mgl_get_slice(_mgl_slice &s, HCDT x, HCDT y, HCDT z, HCDT a, char dir, floa } } //----------------------------------------------------------------------------- -void mgl_cont3_xyz_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_get_slice_md(_mgl_slice &s, const mglData *x, const mglData *y, const mglData *z, const mglData *a, char dir, mreal d, bool both) { - long n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Cont3"); return; } - bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Cont3"); return; } + register long i,j,i0,i1,n=a->nx,m=a->ny,l=a->nz, nx=1,ny=1,p; + + if(dir=='x') { nx = m; ny = l; if(d<0) d = n/2.; } + if(dir=='y') { nx = n; ny = l; if(d<0) d = m/2.; } + if(dir=='z') { nx = n; ny = m; if(d<0) d = l/2.; } + s.x.Create(nx,ny); s.y.Create(nx,ny); + s.z.Create(nx,ny); s.a.Create(nx,ny); + p = long(d); d -= p; + if(dir=='x' && p>=n-1) { d+=p-n+2; p=n-2; } + if(dir=='y' && p>=m-1) { d+=p-m+2.; p=m-2; } + if(dir=='z' && p>=l-1) { d+=p-l+2; p=l-2; } + mreal v; + + if(both) + { + if(dir=='x') for(j=0;ja[i1]*(1-d) + x->a[i1+1]*d; + s.y.a[i0] = y->a[i1]*(1-d) + y->a[i1+1]*d; + s.z.a[i0] = z->a[i1]*(1-d) + z->a[i1+1]*d; + s.a.a[i0] = a->a[i1]*(1-d) + a->a[i1+1]*d; + } + if(dir=='y') for(j=0;ja[i1]*(1-d) + x->a[i1+n]*d; + s.y.a[i0] = y->a[i1]*(1-d) + y->a[i1+n]*d; + s.z.a[i0] = z->a[i1]*(1-d) + z->a[i1+n]*d; + s.a.a[i0] = a->a[i1]*(1-d) + a->a[i1+n]*d; + } + if(dir=='z') for(j=0;ja[i1]*(1-d) + x->a[i1+n*m]*d; + s.y.a[i0] = y->a[i1]*(1-d) + y->a[i1+n*m]*d; + s.z.a[i0] = z->a[i1]*(1-d) + z->a[i1+n*m]*d; + s.a.a[i0] = a->a[i1]*(1-d) + a->a[i1+n*m]*d; + } + } + else // x, y, z -- vectors + { + if(dir=='x') + { + v = x->a[p]*(1-d)+x->a[p+1]*d; + for(j=0;ja[i]; s.z.a[i0] = z->a[j]; + s.a.a[i0] = a->a[i1]*(1-d) + a->a[i1+1]*d; + } + } + if(dir=='y') + { + v = y->a[p]*(1-d)+y->a[p+1]*d; + for(j=0;ja[i]; s.z.a[i0] = z->a[j]; + s.a.a[i0] = a->a[i1]*(1-d) + a->a[i1+n]*d; + } + } + if(dir=='z') + { + v = z->a[p]*(1-d)+z->a[p+1]*d; + for(j=0;ja[i]; s.y.a[i0] = y->a[j]; + s.a.a[i0] = a->a[i1]*(1-d) + a->a[i1+n*m]*d; + } + } + } +} +//----------------------------------------------------------------------------- +void mgl_cont3_xyz_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, mreal sVal, const char *opt) +{ + bool both = mgl_isboth(x,y,z,a); + if(mgl_check_dim3(gr,both,x,y,z,a,0,"Cont3")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Cont3",cgid++); char dir='y'; @@ -987,65 +1092,71 @@ void mgl_cont3_xyz_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, HCDT a, const ch gr->SetPenPal(sch); _mgl_slice s; - mgl_get_slice(s,x,y,z,a,dir,sVal,both); + const mglData *mx = dynamic_cast(x); + const mglData *my = dynamic_cast(y); + const mglData *mz = dynamic_cast(z); + const mglData *ma = dynamic_cast(a); + if(mx&&my&&mz&&ma) mgl_get_slice_md(s,mx,my,mz,ma,dir,sVal,both); + else mgl_get_slice(s,x,y,z,a,dir,sVal,both); for(long i=0;iGetNx();i++) { - float v0 = v->v(i); + mreal v0 = v->v(i); mgl_cont_gen(gr,v0,&s.a,&s.x,&s.y,&s.z,gr->GetC(ss,v0),text,0); } gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_cont3_val(HMGL gr, HCDT v, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_cont3_val(HMGL gr, HCDT v, HCDT a, const char *sch, mreal sVal, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2 || a->GetNz()<2) - { gr->SetWarn(mglWarnLow,"Cont3"); return; } gr->SaveState(opt); mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_cont3_xyz_val(gr,v,&x,&y,&z,a,sch,sVal,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_cont3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_cont3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, mreal sVal, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont3"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont3"); gr->LoadState(); return; } mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); mgl_cont3_xyz_val(gr,&v,x,y,z,a,sch,sVal,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_cont3(HMGL gr, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_cont3(HMGL gr, HCDT a, const char *sch, mreal sVal, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont3"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Cont3"); gr->LoadState(); return; } mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); mgl_cont3_val(gr,&v,a,sch,sVal,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_cont3_xyz_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_cont3_xyz_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_cont3_xyz_val(_GR_, _DA_(v), _DA_(x), _DA_(y), _DA_(z), _DA_(a), s, *sVal, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_cont3_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_cont3_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_cont3_val(_GR_, _DA_(v), _DA_(a), s, *sVal, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_cont3_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_cont3_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_cont3_xyz(_GR_, _DA_(x), _DA_(y), _DA_(z), _DA_(a), s, *sVal, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_cont3_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_cont3_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_cont3(_GR_, _DA_(a), s, *sVal, o); delete []o; delete []s; } @@ -1054,13 +1165,11 @@ void mgl_cont3_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sVal, const // Dens3 series // //----------------------------------------------------------------------------- -void mgl_dens3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_dens3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, mreal sVal, const char *opt) { - long n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Dens3"); return; } - bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Dens3"); return; } + bool both = mgl_isboth(x,y,z,a); + if(mgl_check_dim3(gr,both,x,y,z,a,0,"Dens3")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Dens3",cgid++); char dir='y'; @@ -1068,29 +1177,33 @@ void mgl_dens3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, flo if(sch && strchr(sch,'z')) dir='z'; _mgl_slice s; - mgl_get_slice(s,x,y,z,a,dir,sVal,both); + const mglData *mx = dynamic_cast(x); + const mglData *my = dynamic_cast(y); + const mglData *mz = dynamic_cast(z); + const mglData *ma = dynamic_cast(a); + if(mx&&my&&mz&&ma) mgl_get_slice_md(s,mx,my,mz,ma,dir,sVal,both); + else mgl_get_slice(s,x,y,z,a,dir,sVal,both); mgl_surfc_xy(gr,&s.x,&s.y,&s.z,&s.a,sch,0); } //----------------------------------------------------------------------------- -void mgl_dens3(HMGL gr, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_dens3(HMGL gr, HCDT a, const char *sch, mreal sVal, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2 || a->GetNz()<2) - { gr->SetWarn(mglWarnLow,"Dens3"); return; } gr->SaveState(opt); mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_dens3_xyz(gr,&x,&y,&z,a,sch,sVal,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_dens3_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_dens3_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_dens3_xyz(_GR_, _DA_(x), _DA_(y), _DA_(z), _DA_(a), s, *sVal, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_dens3_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_dens3_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_dens3(_GR_, _DA_(a), s, *sVal, o); delete []o; delete []s; } @@ -1099,13 +1212,11 @@ mgl_dens3(_GR_, _DA_(a), s, *sVal, o); delete []o; delete []s; } // Grid3 series // //----------------------------------------------------------------------------- -void mgl_grid3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_grid3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, mreal sVal, const char *opt) { - long n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Grid3"); return; } - bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Grid3"); return; } + bool both = mgl_isboth(x,y,z,a); + if(mgl_check_dim3(gr,both,x,y,z,a,0,"Grid3")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Grid3",cgid++); char dir='y'; @@ -1113,29 +1224,33 @@ void mgl_grid3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, flo if(sch && strchr(sch,'z')) dir='z'; _mgl_slice s; - mgl_get_slice(s,x,y,z,a,dir,sVal,both); + const mglData *mx = dynamic_cast(x); + const mglData *my = dynamic_cast(y); + const mglData *mz = dynamic_cast(z); + const mglData *ma = dynamic_cast(a); + if(mx&&my&&mz&&ma) mgl_get_slice_md(s,mx,my,mz,ma,dir,sVal,both); + else mgl_get_slice(s,x,y,z,a,dir,sVal,both); mgl_mesh_xy(gr,&s.x,&s.y,&s.z,sch,0); } //----------------------------------------------------------------------------- -void mgl_grid3(HMGL gr, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_grid3(HMGL gr, HCDT a, const char *sch, mreal sVal, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2 || a->GetNz()<2) - { gr->SetWarn(mglWarnLow,"Grid3"); return; } gr->SaveState(opt); mglData x(a->GetNx()), y(a->GetNy()), z(a->GetNz()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_grid3_xyz(gr,&x,&y,&z,a,sch,sVal,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_grid3_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_grid3_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_grid3_xyz(_GR_, _DA_(x), _DA_(y), _DA_(z), _DA_(a), s, *sVal, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_grid3_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_grid3_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_grid3(_GR_, _DA_(a), s, *sVal, o); delete []o; delete []s; } @@ -1144,13 +1259,11 @@ mgl_grid3(_GR_, _DA_(a), s, *sVal, o); delete []o; delete []s; } // ContF3 series // //----------------------------------------------------------------------------- -void mgl_contf3_xyz_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_contf3_xyz_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, mreal sVal, const char *opt) { - long n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"ContF3"); return; } - bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"ContF3"); return; } + bool both = mgl_isboth(x,y,z,a); + if(mgl_check_dim3(gr,both,x,y,z,a,0,"ContF3")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("ContF3",cgid++); char dir='y'; @@ -1159,64 +1272,70 @@ void mgl_contf3_xyz_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, HCDT a, const c long ss=gr->AddTexture(sch); _mgl_slice s; - mgl_get_slice(s,x,y,z,a,dir,sVal,both); + const mglData *mx = dynamic_cast(x); + const mglData *my = dynamic_cast(y); + const mglData *mz = dynamic_cast(z); + const mglData *ma = dynamic_cast(a); + if(mx&&my&&mz&&ma) mgl_get_slice_md(s,mx,my,mz,ma,dir,sVal,both); + else mgl_get_slice(s,x,y,z,a,dir,sVal,both); for(long i=0;iGetNx()-1;i++) { - float v0 = v->v(i); + mreal v0 = v->v(i); mgl_contf_gen(gr,v0,v->v(i+1),&s.a,&s.x,&s.y,&s.z,gr->GetC(ss,v0),0); } gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_contf3_val(HMGL gr, HCDT v, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_contf3_val(HMGL gr, HCDT v, HCDT a, const char *sch, mreal sVal, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2 || a->GetNz()<2) - { gr->SetWarn(mglWarnLow,"ContF3"); return; } gr->SaveState(opt); mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_contf3_xyz_val(gr,v,&x,&y,&z,a,sch,sVal,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_contf3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_contf3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, mreal sVal, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"ContF3"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"ContF3"); gr->LoadState(); return; } mglData v(Num+2); v.Fill(gr->Min.c, gr->Max.c); mgl_contf3_xyz_val(gr,&v,x,y,z,a,sch,sVal,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_contf3(HMGL gr, HCDT a, const char *sch, float sVal, const char *opt) +void mgl_contf3(HMGL gr, HCDT a, const char *sch, mreal sVal, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?7:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"ContF3"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"ContF3"); gr->LoadState(); return; } mglData v(Num+2); v.Fill(gr->Min.c, gr->Max.c); mgl_contf3_val(gr,&v,a,sch,sVal,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_contf3_xyz_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_contf3_xyz_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_contf3_xyz_val(_GR_, _DA_(v), _DA_(x), _DA_(y), _DA_(z), _DA_(a), s, *sVal, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_contf3_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_contf3_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_contf3_val(_GR_, _DA_(v), _DA_(a), s, *sVal, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_contf3_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_contf3_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_contf3_xyz(_GR_, _DA_(x), _DA_(y), _DA_(z), _DA_(a), s, *sVal, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_contf3_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sVal, const char *opt,int l,int lo) +void mgl_contf3_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sVal, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_contf3(_GR_, _DA_(a), s, *sVal, o); @@ -1231,7 +1350,7 @@ long mgl_find_prev(long i, long pc, long *nn) for(long k=0;kReserve(pc*82); else gr->Reserve(pc*82); for(i=0;iGetNx(), m=a->GetNy(); if(n<2 || m<2 || x->GetNx()*x->GetNy()!=n*m || y->GetNx()*y->GetNy()!=n*m) { gr->SetWarn(mglWarnDim,"ContGen"); return; } mglPoint *kk = new mglPoint[2*n*m],*pp = new mglPoint[2*n*m],p; - float d, kx, ky; - register long i,j,k, pc=0; + mreal d, kx, ky; + register long i,j,k, pc=0,i0; // Usually number of points is much smaller. So, there is no reservation. // gr->Reserve(2*n*m); - // add intersection point of isoline and Y axis - for(j=0;j(x); + const mglData *my = dynamic_cast(y); + const mglData *ma = dynamic_cast(a); + if(mx&&my&&ma) for(j=0;jStop) { delete []kk; delete []pp; return; } - d = mgl_d(val,a->v(i,j,ak),a->v(i+1,j,ak)); + i0 = i+n*j; + d = (ia[i0+n*m*ak],ma->a[i0+1+n*m*ak]):-1; if(d>=0 && d<1) { - pp[pc] = mglPoint(x->v(i,j)*(1-d)+x->v(i+1,j)*d, - y->v(i,j)*(1-d)+y->v(i+1,j)*d); + pp[pc] = mglPoint(mx->a[i0]*(1-d)+mx->a[i0+1]*d, my->a[i0]*(1-d)+my->a[i0+1]*d); kk[pc] = mglPoint(i+d,j); pc++; } + d = (ja[i0+n*m*ak],ma->a[i0+n*m*ak+n]):-1; + if(d>=0 && d<1) + { + pp[pc] = mglPoint(mx->a[i0]*(1-d)+mx->a[i0+n]*d, my->a[i0]*(1-d)+my->a[i0+n]*d); + kk[pc] = mglPoint(i,j+d); pc++; + } } - // add intersection point of isoline and X axis - for(j=0;jStop) { delete []kk; delete []pp; return; } - d = mgl_d(val,a->v(i,j,ak),a->v(i,j+1,ak)); + register mreal va=a->v(i,j,ak),vx=x->v(i,j),vy=y->v(i,j); + d = (iv(i+1,j,ak)):-1; + if(d>=0 && d<1) + { + pp[pc] = mglPoint(vx*(1-d)+x->v(i+1,j)*d, vy*(1-d)+y->v(i+1,j)*d); + kk[pc] = mglPoint(i+d,j); pc++; + } + d = (jv(i,j+1,ak)):-1; if(d>=0 && d<1) { - pp[pc] = mglPoint(x->v(i,j)*(1-d)+x->v(i,j+1)*d, - y->v(i,j)*(1-d)+y->v(i,j+1)*d); + pp[pc] = mglPoint(vx*(1-d)+x->v(i,j+1)*d, vy*(1-d)+y->v(i,j+1)*d); kk[pc] = mglPoint(i,j+d); pc++; } } @@ -1356,10 +1489,8 @@ void mgl_axial_gen(HMGL gr, float val, HCDT a, HCDT x, HCDT y, float c, char dir void mgl_axial_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Axial"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Axial"); return; } - bool both = x->GetNx()*x->GetNy()==m*n && y->GetNx()*y->GetNy()==m*n; - if(y->GetNx()!=z->GetNy() && !both) { gr->SetWarn(mglWarnDim, "Axial"); return; } + if(mgl_check_dim2(gr,x,y,z,0,"Axial")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Axial",cgid++); @@ -1369,16 +1500,19 @@ void mgl_axial_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, if(sch && strchr(sch,'z')) dir = 'z'; mglData xx, yy; - if(!both) // make + if(x->GetNx()*x->GetNy()!=m*n || y->GetNx()*y->GetNy()!=m*n) // make { - xx.Create(z->GetNx(), z->GetNy()); - yy.Create(z->GetNx(), z->GetNy()); - for(j=0;j(x); + const mglData *my = dynamic_cast(y); + if(mx && my) for(i=0;ia[i]; yy.a[i+n*j] = my->a[j]; } + else for(i=0;iv(i); yy.a[i+n*j] = y->v(j); } x = &xx; y = &yy; } // x, y -- have the same size z - float v0; + mreal v0; bool wire = sch && strchr(sch,'#'); for(j=0;jGetNz();j++) for(i=0;iGetNx();i++) { @@ -1391,33 +1525,37 @@ void mgl_axial_xy_val(HMGL gr, HCDT v, HCDT x, HCDT y, HCDT z, const char *sch, //----------------------------------------------------------------------------- void mgl_axial_val(HMGL gr, HCDT v, HCDT a, const char *sch, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2) { gr->SetWarn(mglWarnLow,"Axial"); return; } + register long n=a->GetNx(), m=a->GetNy(); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Axial"); return; } gr->SaveState(opt); - mglData x(a->GetNx(),a->GetNy()), y(a->GetNx(),a->GetNy()); + mglData x(n, m), y(n, m); if(gr->Max.x*gr->Min.x>=0) x.Fill(gr->Min.x,gr->Max.x,'x'); else x.Fill(0,gr->Max.x,'x'); y.Fill(gr->Min.y,gr->Max.y,'y'); mgl_axial_xy_val(gr,v,&x,&y,a,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_axial_xy(HMGL gr, HCDT x, HCDT y, HCDT a, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?3:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Axial"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Axial"); gr->LoadState(); return; } mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); mgl_axial_xy_val(gr,&v,x,y,a,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_axial(HMGL gr, HCDT a, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long Num = mgl_isnan(r)?3:long(r+0.5); - if(Num<1) { gr->SetWarn(mglWarnCnt,"Axial"); return; } + if(Num<1) { gr->SetWarn(mglWarnCnt,"Axial"); gr->LoadState(); return; } mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); mgl_axial_val(gr,&v,a,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_axial_xy_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -1460,10 +1598,17 @@ void mgl_torus(HMGL gr, HCDT r, HCDT z, const char *sch, const char *opt) if(sch && strchr(sch,'x')) dir = 'x'; if(sch && strchr(sch,'z')) dir = 'z'; - float c = gr->GetC(ss,gr->Min.c); + mreal c = gr->GetC(ss,gr->Min.c); + const mglData *mr = dynamic_cast(r); + const mglData *mz = dynamic_cast(z); for(j=0;jGetNy();j++) { - for(i=0;ia[i+n*j], mz->a[i+n*j]); + } + else for(i=0;iv(i,j), z->v(i,j)); diff --git a/src/crust.cpp b/src/crust.cpp index f7cf7fb..5903b47 100644 --- a/src/crust.cpp +++ b/src/crust.cpp @@ -17,7 +17,6 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include #include "mgl2/other.h" #include "mgl2/data.h" @@ -29,8 +28,8 @@ void mgl_triplot_xyzc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt) { long n = x->GetNx(), m = nums->GetNy(); - if(y->GetNx()!=n || z->GetNx()!=n || nums->GetNx()<3) { gr->SetWarn(mglWarnLow,"TriPlot"); return; } - if(a->GetNx()!=m && a->GetNx()!=n) { gr->SetWarn(mglWarnLow,"TriPlot"); return; } + if(mgl_check_trig(gr,nums,x,y,z,a,"TriPlot")) return; + long ss=gr->AddTexture(sch); gr->SaveState(opt); static int cgid=1; gr->StartGroup("TriPlot",cgid++); @@ -70,12 +69,14 @@ void mgl_triplot_xyzc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const k2 = long(nums->v(1,i)+0.5); k3 = long(nums->v(2,i)+0.5); if(!wire) + { q = mglPoint(x->v(k2)-x->v(k1), y->v(k2)-y->v(k1), z->v(k2)-z->v(k1)) ^ mglPoint(x->v(k3)-x->v(k1), y->v(k3)-y->v(k1), z->v(k3)-z->v(k1)); - // try be sure that in the same direction ... but it is so slow :( - if(pp[k1]*q<0) q*=-1; pp[k1] += q; - if(pp[k2]*q<0) q*=-1; pp[k2] += q; - if(pp[k3]*q<0) q*=-1; pp[k3] += q; + q.Normalize(); + // try be sure that in the same direction ... + if(q.z<0) q *= -1; + pp[k1] += q; pp[k2] += q; pp[k3] += q; + } } for(i=0;iSaveState(opt); - mglData z(x->GetNx()); z.Fill(gr->Min.z,gr->Min.z); + mglData z(x->GetNx()); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_triplot_xyzc(gr,nums,x,y,&z,&z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_triplot_xyzc_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int l,int lo) @@ -135,8 +138,8 @@ void mgl_triplot_xy_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, void mgl_quadplot_xyzc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt) { long n = x->GetNx(), m = nums->GetNy(); - if(y->GetNx()!=n || z->GetNx()!=n || nums->GetNx()<4) { gr->SetWarn(mglWarnLow,"QuadPlot"); return; } - if(a->GetNx()!=m && a->GetNx()!=n) { gr->SetWarn(mglWarnLow,"QuadPlot"); return; } + if(mgl_check_trig(gr,nums,x,y,z,a,"QuadPlot",4)) return; + long ss=gr->AddTexture(sch); gr->SaveState(opt); static int cgid=1; gr->StartGroup("QuadPlot",cgid++); @@ -187,17 +190,16 @@ void mgl_quadplot_xyzc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const if(wire) pp[k1]=pp[k2]=pp[k3]=pp[k4]=mglPoint(NAN,NAN); else { - q = (p2-p1) ^ (p3-p1); if(pp[k1]*q<0) q*=-1; pp[k1] += q; - q = (p2-p4) ^ (p3-p4); if(pp[k2]*q<0) q*=-1; pp[k2] += q; - q = (p1-p2) ^ (p4-p2); if(pp[k3]*q<0) q*=-1; pp[k3] += q; - q = (p1-p4) ^ (p4-p3); if(pp[k4]*q<0) q*=-1; pp[k4] += q; + q = (p2-p1) ^ (p3-p1); if(q.z<0) q*=-1; pp[k1] += q; + q = (p2-p4) ^ (p3-p4); if(q.z<0) q*=-1; pp[k2] += q; + q = (p1-p2) ^ (p4-p2); if(q.z<0) q*=-1; pp[k3] += q; + q = (p1-p4) ^ (p4-p3); if(q.z<0) q*=-1; pp[k4] += q; } } for(i=0;iStop) { delete []kk; delete []pp; return; } - q = mglPoint(x->v(i), y->v(i), z->v(i)); - kk[i] = gr->AddPnt(q,gr->GetC(ss,a->v(i)),pp[i]); + kk[i] = gr->AddPnt(mglPoint(x->v(i), y->v(i), z->v(i)),gr->GetC(ss,a->v(i)), pp[i]); } for(i=0;iSaveState(opt); mglData z(x->GetNx()); z.Fill(gr->Min.z,gr->Min.z); mgl_quadplot_xyzc(gr,nums,x,y,&z,&z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_quadplot_xyzc_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *sch, const char *opt,int l,int lo) @@ -249,9 +252,9 @@ void mgl_quadplot_xy_(uintptr_t *gr, uintptr_t *nums, uintptr_t *x, uintptr_t *y // TriCont series // //----------------------------------------------------------------------------- -void mgl_tricont_line(HMGL gr, float val, long k1, long k2, long k3, HCDT x, HCDT y, HCDT z, HCDT a, bool zVal,float c) +void mgl_tricont_line(HMGL gr, mreal val, long k1, long k2, long k3, HCDT x, HCDT y, HCDT z, HCDT a, bool zVal,mreal c) { - float d1,d2; + mreal d1,d2; mglPoint p1,p2,n; d1 = mgl_d(val,a->v(k1),a->v(k2)); d2 = mgl_d(val,a->v(k1),a->v(k3)); @@ -270,12 +273,12 @@ void mgl_tricont_line(HMGL gr, float val, long k1, long k2, long k3, HCDT x, HCD void mgl_tricont_xyzcv(HMGL gr, HCDT v, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt) { long n = x->GetNx(), m = nums->GetNy(); - if(y->GetNx()!=n || z->GetNx()!=n || nums->GetNx()<3) { gr->SetWarn(mglWarnLow,"TriCont"); return; } - if(a->GetNx()!=m && a->GetNx()!=n) { gr->SetWarn(mglWarnLow,"TriCont"); return; } + if(mgl_check_trig(gr,nums,x,y,z,a,"TriCont")) return; + long ss=gr->AddTexture(sch); gr->SaveState(opt); static int cgid=1; gr->StartGroup("TriCont",cgid++); - float val; + mreal val; register long i,k; long k1,k2,k3; bool zVal = (sch && strchr(sch,'_')); @@ -286,7 +289,7 @@ void mgl_tricont_xyzcv(HMGL gr, HCDT v, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT k2 = long(nums->v(1,i)+0.1); if(k2<0 || k2>=n) continue; k3 = long(nums->v(2,i)+0.1); if(k3<0 || k3>=n) continue; val = v->v(k); - float c = gr->GetC(ss,val); + mreal c = gr->GetC(ss,val); mgl_tricont_line(gr,val, k1,k2,k3,x,y,z,a,zVal,c); mgl_tricont_line(gr,val, k2,k1,k3,x,y,z,a,zVal,c); mgl_tricont_line(gr,val, k3,k2,k1,x,y,z,a,zVal,c); @@ -295,11 +298,12 @@ void mgl_tricont_xyzcv(HMGL gr, HCDT v, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT //----------------------------------------------------------------------------- void mgl_tricont_xyzc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long n = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); mglData v(n); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(n+1); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(n+1); mgl_tricont_xyzcv(gr,&v,nums,x,y,z,a,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tricont_xyc(HMGL gr, HCDT nums, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) @@ -375,9 +379,9 @@ void mgl_dots_a_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintpt // mglTriangulation // //----------------------------------------------------------------------------- -long mgl_crust(long n,mglPoint *pp,long **nn,float ff); -HMDT mgl_triangulation_3d(HCDT x, HCDT y, HCDT z, float er) -{ +long mgl_crust(long n,mglPoint *pp,long **nn,mreal ff); +HMDT mgl_triangulation_3d(HCDT x, HCDT y, HCDT z) +{ // TODO: should be used s-hull or q-hull mglData *nums=new mglData; long n = x->GetNx(), m; if(y->GetNx()!=n || z->GetNx()!=n) return nums; @@ -385,7 +389,7 @@ HMDT mgl_triangulation_3d(HCDT x, HCDT y, HCDT z, float er) mglPoint *pp = new mglPoint[n]; long *nn=0; for(i=0;iv(i), y->v(i), z->v(i)); - m = mgl_crust(n,pp,&nn,er); + m = mgl_crust(n,pp,&nn,0); if(m>0) { @@ -395,16 +399,110 @@ HMDT mgl_triangulation_3d(HCDT x, HCDT y, HCDT z, float er) delete []pp; free(nn); return nums; } //----------------------------------------------------------------------------- -HMDT mgl_triangulation_2d(HCDT x, HCDT y, float er) +#include "s_hull/s_hull_pro.h" +HMDT mgl_triangulation_2d(HCDT x, HCDT y) { - mglData z(x->GetNx()); - return mgl_triangulation_3d(x,y,&z,er); + mglData *nums=new mglData; + register long n = x->GetNx(), m,i; + if(y->GetNx()!=n) return nums; + // use s-hull here + std::vector pts; + Shx pt; + + for(i=0;iv(i); pt.c = y->v(i); + pt.id = i; pts.push_back(pt); + } + std::vector triads; + s_hull_pro(pts, triads); + m = triads.size(); + nums->Create(3,m); + for(i=0;ia[3*i] = triads[i].a; + nums->a[3*i+1] = triads[i].b; + nums->a[3*i+2] = triads[i].c; + } + return nums; } //----------------------------------------------------------------------------- -uintptr_t mgl_triangulation_3d_(uintptr_t *x, uintptr_t *y, uintptr_t *z, float *er) -{ return uintptr_t(mgl_triangulation_3d(_DA_(x),_DA_(y),_DA_(z),*er)); } -uintptr_t mgl_triangulation_2d_(uintptr_t *x, uintptr_t *y, float *er) -{ return uintptr_t(mgl_triangulation_2d(_DA_(x),_DA_(y),*er)); } +uintptr_t mgl_triangulation_3d_(uintptr_t *x, uintptr_t *y, uintptr_t *z) +{ return uintptr_t(mgl_triangulation_3d(_DA_(x),_DA_(y),_DA_(z))); } +uintptr_t mgl_triangulation_2d_(uintptr_t *x, uintptr_t *y) +{ return uintptr_t(mgl_triangulation_2d(_DA_(x),_DA_(y))); } +//----------------------------------------------------------------------------- +// +// DataGrid +// +//----------------------------------------------------------------------------- +void *mgl_grid_t(void *par) +{ + mglThreadD *t=(mglThreadD *)par; + long nx=t->p[0],ny=t->p[1]; + register long i0, k1,k2,k3; + mreal *b=t->a; + const mreal *x=t->b, *y=t->c, *d=t->d, *z=t->e; + for(i0=t->id;i0n;i0+=mglNumThr) + { + k1 = long(d[3*i0]); k2 = long(d[3*i0+1]); k3 = long(d[3*i0+2]); + mreal dxu,dxv,dyu,dyv; + mglPoint d1=mglPoint(x[k2]-x[k1],y[k2]-y[k1],z[k2]-z[k1]), d2=mglPoint(x[k3]-x[k1],y[k3]-y[k1],z[k3]-z[k1]), p; + + dxu = d2.x*d1.y - d1.x*d2.y; + if(fabs(dxu)<1e-5) continue; // points lies on the same line + dyv =-d1.x/dxu; dxv = d1.y/dxu; + dyu = d2.x/dxu; dxu =-d2.y/dxu; + + long x1,y1,x2,y2; + x1 = long(fmin(fmin(x[k1],x[k2]),x[k3])); // bounding box + y1 = long(fmin(fmin(y[k1],y[k2]),y[k3])); + x2 = long(fmax(fmax(x[k1],x[k2]),x[k3])); + y2 = long(fmax(fmax(y[k1],y[k2]),y[k3])); + x1 = x1>0 ? x1:0; x2 = x20 ? y1:0; y2 = y2x2) | (y1>y2)) continue; + + register mreal u,v,xx,yy, x0 = x[k1], y0 = y[k1]; + register long i,j; + for(i=x1;i<=x2;i++) for(j=y1;j<=y2;j++) + { + xx = (i-x0); yy = (j-y0); + u = dxu*xx+dyu*yy; v = dxv*xx+dyv*yy; + if((u<0) | (v<0) | (u+v>1)) continue; + b[i+nx*j] = z[k1] + d1.z*u + d2.z*v; + } + } + return 0; +} +void mgl_data_grid(HMGL gr, HMDT d, HCDT xdat, HCDT ydat, HCDT zdat, const char *opt) +{ // NOTE: only for mglData + const mglData *x = dynamic_cast(xdat); + const mglData *y = dynamic_cast(ydat); + const mglData *z = dynamic_cast(zdat); + if(!x | !y | !z) return; + long n=x->nx; + if((n<3) | (y->nx!=n) | (z->nx!=n)) return; + + gr->SaveState(opt); + mglData *nums = mgl_triangulation_2d(x,y); + if(nums->nx<3) { delete nums; return; } + long nn = nums->ny, par[3]={d->nx,d->ny,d->nz}; + mreal xx[4]={gr->Min.x,0, gr->Min.y,0}; + if(d->nx>1) xx[1] = (d->nx-1.)/(gr->Max.x-gr->Min.x); + if(d->ny>1) xx[3] = (d->ny-1.)/(gr->Max.y-gr->Min.y); + + register long i; + mreal *xc=new mreal[n], *yc=new mreal[n]; + for(i=0;ia[i]-xx[0]); yc[i]=xx[3]*(y->a[i]-xx[2]); } + for(long i=0;inx*d->ny*d->nz;i++) d->a[i] = NAN; + + mglStartThread(mgl_grid_t,0,nn,d->a,xc,yc,par,0,nums->a,z->a); + gr->LoadState(); delete nums; delete []xc; delete []yc; +} +void mgl_data_grid_(uintptr_t *gr, uintptr_t *d, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *opt,int lo) +{ char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; + mgl_data_grid(_GR_,_DT_,_DA_(x),_DA_(y),_DA_(z),o); delete []o; } //----------------------------------------------------------------------------- // // Crust series @@ -414,7 +512,7 @@ void mgl_crust(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt { if(y->GetNx()!=x->GetNx() || z->GetNx()!=x->GetNx()) { gr->SetWarn(mglWarnDim,"Crust"); return; } - HMDT nums = mgl_triangulation_3d(x, y, z, 0); + HMDT nums = mgl_triangulation_3d(x, y, z); mgl_triplot_xyzc(gr,nums,x,y,z,z,sch,opt); mgl_delete_data(nums); } @@ -458,7 +556,7 @@ long mgl_insert_trig(long i1,long i2,long i3,long **n) long mgl_get_next(long k1,long n,long *,long *set,mglPoint *qq) { long i,j=-1; - float r,rm=FLT_MAX; + mreal r,rm=FLT_MAX; for(i=0;i0) continue; @@ -468,10 +566,10 @@ long mgl_get_next(long k1,long n,long *,long *set,mglPoint *qq) return j; } //----------------------------------------------------------------------------- -long mgl_crust(long n,mglPoint *pp,long **nn,float ff) +long mgl_crust(long n,mglPoint *pp,long **nn,mreal ff) { // TODO: update to normal algorithm register long i,j; - register float r,rm,rs; + register mreal r,rm,rs; if(ff<=0) ff=2; for(rs=0,i=0;i -#include -#include #include "mgl2/data.h" #include "mgl2/eval.h" @@ -58,7 +55,7 @@ void mgl_set_num_thr(int) { mglNumThr = 1; } #endif //----------------------------------------------------------------------------- void mglStartThread(void *(*func)(void *), void (*post)(mglThreadD *,mreal *), long n, mreal *a, - const mreal *b, const mreal *c, const long *p, void *v, const mreal *d, const mreal *e, char *s) + const mreal *b, const mreal *c, const long *p, void *v, const mreal *d, const mreal *e, const char *s) { if(!func) return; #if MGL_HAVE_PTHREAD @@ -178,7 +175,7 @@ void *mgl_smth_z(void *par) } return 0; } -void mgl_data_smooth(HMDT d, const char *dirs, float delta) +void mgl_data_smooth(HMDT d, const char *dirs, mreal delta) { long Type = SMOOTH_QUAD_5; if(strchr(dirs,'0') || strchr(dirs,'1')) return; @@ -209,7 +206,7 @@ void mgl_data_smooth(HMDT d, const char *dirs, float delta) } delete []b; } -void mgl_data_smooth_(uintptr_t *d, const char *dir, float *delta,int l) +void mgl_data_smooth_(uintptr_t *d, const char *dir, mreal *delta,int l) { char *s=new char[l+1]; memcpy(s,dir,l); s[l]=0; mgl_data_smooth(_DT_,s,*delta); delete []s; } //----------------------------------------------------------------------------- @@ -567,7 +564,7 @@ void mgl_data_mirror_(uintptr_t *d, const char *dir,int l) { char *s=new char[l+1]; memcpy(s,dir,l); s[l]=0; mgl_data_mirror(_DT_,s); delete []s; } //----------------------------------------------------------------------------- -float mgl_data_linear(HCDT d, float x,float y,float z) +mreal mgl_data_linear(HCDT d, mreal x,mreal y,mreal z) { long kx=long(x), ky=long(y), kz=long(z); mreal b0,b1; @@ -603,7 +600,7 @@ float mgl_data_linear(HCDT d, float x,float y,float z) return b0 + z*(b1-b0); } //----------------------------------------------------------------------------- -float mgl_data_spline(HCDT d, float x,float y,float z) +mreal mgl_data_spline(HCDT d, mreal x,mreal y,mreal z) { const mglData *dd=dynamic_cast(d); if(!d) return 0; // NOTE: don't support general arrays @@ -830,9 +827,9 @@ void mglFillP(long x, const mreal *a,long nx,mreal _p[4]) _p[3]=s[0]+s[1]+2*(f[0]-f[1]); } //----------------------------------------------------------------------------- -float mgl_data_spline_(uintptr_t *d, float *x,float *y,float *z) +mreal mgl_data_spline_(uintptr_t *d, mreal *x,mreal *y,mreal *z) { return mgl_data_spline(_DA_(d),*x,*y,*z); } -float mgl_data_linear_(uintptr_t *d, float *x,float *y,float *z) +mreal mgl_data_linear_(uintptr_t *d, mreal *x,mreal *y,mreal *z) { return mgl_data_linear(_DA_(d),*x,*y,*z); } //----------------------------------------------------------------------------- void mgl_data_crop(HMDT d, long n1, long n2, char dir) @@ -874,7 +871,7 @@ void mgl_data_crop(HMDT d, long n1, long n2, char dir) void mgl_data_crop_(uintptr_t *d, int *n1, int *n2, const char *dir,int) { mgl_data_crop(_DT_,*n1,*n2,*dir); } //----------------------------------------------------------------------------- -float mgl_data_last(HCDT d, const char *cond, long *i, long *j, long *k) +mreal mgl_data_last(HCDT d, const char *cond, long *i, long *j, long *k) { long nx=d->GetNx(),ny=d->GetNy(),nz=d->GetNz(); if(!cond) cond = "u"; @@ -892,12 +889,12 @@ float mgl_data_last(HCDT d, const char *cond, long *i, long *j, long *k) *i = i0%nx; *j = (i0/nx)%ny; *k = i0/(nx*ny); return i0>=0 ? d->vthr(i0) : NAN; // NOTE: Return NAN if false } -float mgl_data_last_(uintptr_t *d, const char *cond, int *i, int *j, int *k, int l) +mreal mgl_data_last_(uintptr_t *d, const char *cond, int *i, int *j, int *k, int l) { long ii,jj,kk; char *s=new char[l+1]; memcpy(s,cond,l); s[l]=0; - float res = mgl_data_last(_DT_,s,&ii,&jj,&kk); *i=ii; *j=jj; *k=kk; + mreal res = mgl_data_last(_DT_,s,&ii,&jj,&kk); *i=ii; *j=jj; *k=kk; delete []s; return res; } //----------------------------------------------------------------------------- -float mgl_data_first(HCDT d, const char *cond, long *i, long *j, long *k) +mreal mgl_data_first(HCDT d, const char *cond, long *i, long *j, long *k) { long nx=d->GetNx(),ny=d->GetNy(),nz=d->GetNz(); if(!cond) cond = "u"; @@ -915,9 +912,9 @@ float mgl_data_first(HCDT d, const char *cond, long *i, long *j, long *k) *i = i0%nx; *j = (i0/nx)%ny; *k = i0/(nx*ny); return i0vthr(i0) : NAN; // NOTE: Return NAN if false } -float mgl_data_first_(uintptr_t *d, const char *cond, int *i, int *j, int *k, int l) +mreal mgl_data_first_(uintptr_t *d, const char *cond, int *i, int *j, int *k, int l) { long ii,jj,kk; char *s=new char[l+1]; memcpy(s,cond,l); s[l]=0; - float res = mgl_data_first(_DT_,s,&ii,&jj,&kk); *i=ii; *j=jj; *k=kk; + mreal res = mgl_data_first(_DT_,s,&ii,&jj,&kk); *i=ii; *j=jj; *k=kk; delete []s; return res; } //----------------------------------------------------------------------------- long mgl_data_find(HCDT d, const char *cond, char dir, long i, long j, long k) @@ -958,48 +955,87 @@ int mgl_data_find_any_(uintptr_t *d, const char *cond, int l) { char *s=new char[l+1]; memcpy(s,cond,l); s[l]=0; int res = mgl_data_find_any(_DT_,s); delete []s; return res; } //----------------------------------------------------------------------------- -float mgl_data_momentum_val(HCDT dd, char dir, mreal *x, mreal *w, mreal *s, mreal *k) +mreal mgl_data_momentum_val(HCDT dd, char dir, mreal *x, mreal *w, mreal *s, mreal *k) { long nx=dd->GetNx(),ny=dd->GetNy(),nz=dd->GetNz(); mreal i0=0,i1=0,i2=0,i3=0,i4=0,d,t,v; register long i; - switch(dir) + const mglData *md = dynamic_cast(dd); + if(dd) switch(dir) { - case 'x': - for(i=0;ivthr(i);i0+= v; - i1+= v*d; i2+= v*t; - i3+= v*d*t; i4+= v*t*t; - } - break; - case 'y': - for(i=0;ivthr(i);i0+= v; - i1+= v*d; i2+= v*t; - i3+= v*d*t; i4+= v*t*t; - } - break; - case 'z': - for(i=0;ivthr(i);i0+= v; - i1+= v*d; i2+= v*t; - i3+= v*d*t; i4+= v*t*t; - } - break; - default: // "self-dispersion" - i0 = nx*ny*nz; - for(i=0;ivthr(i); t = v*v; - i1+= v; i2+= t; - i3+= v*t; i4+= t*t; - } + case 'x': + for(i=0;ia[i];i0+= v; + i1+= v*d; i2+= v*t; + i3+= v*d*t; i4+= v*t*t; + } + break; + case 'y': + for(i=0;ia[i];i0+= v; + i1+= v*d; i2+= v*t; + i3+= v*d*t; i4+= v*t*t; + } + break; + case 'z': + for(i=0;ia[i];i0+= v; + i1+= v*d; i2+= v*t; + i3+= v*d*t; i4+= v*t*t; + } + break; + default: // "self-dispersion" + i0 = nx*ny*nz; + for(i=0;ia[i]; t = v*v; + i1+= v; i2+= t; + i3+= v*t; i4+= t*t; + } + } + else switch(dir) + { + case 'x': + for(i=0;ivthr(i);i0+= v; + i1+= v*d; i2+= v*t; + i3+= v*d*t; i4+= v*t*t; + } + break; + case 'y': + for(i=0;ivthr(i);i0+= v; + i1+= v*d; i2+= v*t; + i3+= v*d*t; i4+= v*t*t; + } + break; + case 'z': + for(i=0;ivthr(i);i0+= v; + i1+= v*d; i2+= v*t; + i3+= v*d*t; i4+= v*t*t; + } + break; + default: // "self-dispersion" + i0 = nx*ny*nz; + for(i=0;ivthr(i); t = v*v; + i1+= v; i2+= t; + i3+= v*t; i4+= t*t; + } } if(i0==0) return 0; d=i1/i0; if(x) *x=d; @@ -1008,12 +1044,12 @@ float mgl_data_momentum_val(HCDT dd, char dir, mreal *x, mreal *w, mreal *s, mre if(k) *k=i4/(i0*3); return i0; } -float mgl_data_momentum_val_(uintptr_t *d, char *dir, float *m, float *w, float *s, float *k,int) +mreal mgl_data_momentum_val_(uintptr_t *d, char *dir, mreal *m, mreal *w, mreal *s, mreal *k,int) { mreal mm,ww,ss,kk,aa; aa = mgl_data_momentum_val(_DT_,*dir,&mm,&ww,&ss,&kk); *m=mm; *w=ww; *s=ss; *k=kk; return aa; } //----------------------------------------------------------------------------- -void mgl_data_norm_slice(HMDT d, float v1,float v2,char dir,long keep_en,long sym) +void mgl_data_norm_slice(HMDT d, mreal v1,mreal v2,char dir,long keep_en,long sym) { long nx=d->nx, ny=d->ny, nz=d->nz; mreal *a=d->a; @@ -1084,7 +1120,7 @@ void mgl_data_norm_slice(HMDT d, float v1,float v2,char dir,long keep_en,long sy } memcpy(d->a, b.a, nx*ny*nz*sizeof(mreal)); } -void mgl_data_norm_slice_(uintptr_t *d, float *v1,float *v2,char *dir,int *keep_en,int *sym,int ) +void mgl_data_norm_slice_(uintptr_t *d, mreal *v1,mreal *v2,char *dir,int *keep_en,int *sym,int ) { mgl_data_norm_slice(_DT_,*v1,*v2,*dir,*keep_en,*sym); } //----------------------------------------------------------------------------- const char *mgl_data_info(HCDT d) // NOTE: Not thread safe function! @@ -1291,7 +1327,7 @@ void *mgl_sew_x(void *par) for(i=t->id;ia+i*nx, t->b[0], nx, 1); return 0; } -void mgl_data_sew(HMDT d, const char *dirs, float delta) +void mgl_data_sew(HMDT d, const char *dirs, mreal delta) { long nx=d->nx, ny=d->ny, nz=d->nz; long p[3]={nx,ny,nz}; @@ -1300,7 +1336,7 @@ void mgl_data_sew(HMDT d, const char *dirs, float delta) if(strchr(dirs,'y') && ny>1) mglStartThread(mgl_sew_y,0,nz*nx,d->a,&da,0,p); if(strchr(dirs,'z') && nz>1) mglStartThread(mgl_sew_z,0,nx*ny,d->a,&da,0,p); } -void mgl_data_sew_(uintptr_t *d, const char *dirs, float *da, int l) +void mgl_data_sew_(uintptr_t *d, const char *dirs, mreal *da, int l) { char *s=new char[l+1]; memcpy(s,dirs,l); s[l]=0; mgl_data_sew(_DT_,s,*da); delete []s; } //----------------------------------------------------------------------------- @@ -1324,65 +1360,67 @@ void mgl_data_put_dat(HMDT d, HCDT v, long xx, long yy, long zz) { register long nx=d->nx, ny=d->ny, nz=d->nz; if(xx>=nx || yy>=ny || zz>=nz) return; + const mglData *mv = dynamic_cast(v); mreal *a=d->a, vv=v->v(0); + const mreal *b = mv?mv->a:0; long vx=v->GetNx(), vy=v->GetNy(), vz=v->GetNz(); register long i,j,k; if(xx<0 && yy<0 && zz<0) // whole array { if(vx>=nx && vy>=ny && vz>=nz) for(k=0;kv(i,j,k); + a[i+nx*(j+k*ny)] = b?b[i+vx*(j+k*vy)]:v->v(i,j,k); else if(vx>=nx && vy>=ny) for(k=0;kv(i,j); + a[i+nx*(j+k*ny)] = b?b[i+vx*j]:v->v(i,j); else if(vx>=nx) for(k=0;kv(i); + a[i+nx*k] = b?b[i]:v->v(i); else for(i=0;i=nx && vy>=ny) for(j=0;jv(i,j); + a[i+nx*(j+zz*ny)] = b?b[i+vx*j]:v->v(i,j); else if(vx>=nx) for(j=0;jv(i); + a[i+nx*(j+zz*ny)] = b?b[i]:v->v(i); else for(i=0;i=ny && vy>=nz) for(j=0;jv(i,j); + a[xx+nx*(i+j*ny)] = b?b[i+vx*j]:v->v(i,j); else if(vx>=ny) for(j=0;jv(i); + a[xx+nx*(i+j*ny)] = b?b[i]:v->v(i); else for(i=0;i=nx && vy>=nz) for(j=0;jv(i,j); + a[i+nx*(yy+j*ny)] = b?b[i+vx*j]:v->v(i,j); else if(vx>=nx) for(j=0;jv(i); + a[i+nx*(yy+j*ny)] = b?b[i]:v->v(i); else for(j=0;j=nx) for(i=0;iv(i); + if(vx>=nx) for(i=0;iv(i); else for(i=0;i=ny) for(i=0;iv(i); + if(vx>=ny) for(i=0;iv(i); else for(i=0;i=nz) for(i=0;iv(i); + if(vx>=nz) for(i=0;iv(i); else for(i=0;ia[i+dat->nx*(j+dat->ny*k)]=v; } -void mgl_data_set_value_(uintptr_t *d, float *v, int *i, int *j, int *k) +void mgl_data_set_value(HMDT dat, mreal v, long i, long j, long k) +{ if(i>=0 && inx && j>=0 && jny && k>=0 && knz) dat->a[i+dat->nx*(j+dat->ny*k)]=v; } +void mgl_data_set_value_(uintptr_t *d, mreal *v, int *i, int *j, int *k) { mgl_data_set_value(_DT_,*v,*i,*j,*k); } //----------------------------------------------------------------------------- -float mgl_data_get_value(HCDT dat, long i, long j, long k) -{ return dat->v(i,j,k); } -float mgl_data_get_value_(uintptr_t *d, int *i, int *j, int *k) +mreal mgl_data_get_value(HCDT dat, long i, long j, long k) +{ return (i>=0 && iGetNx() && j>=0 && jGetNy() && k>=0 && kGetNz()) ? dat->v(i,j,k):NAN; } +mreal mgl_data_get_value_(uintptr_t *d, int *i, int *j, int *k) { return mgl_data_get_value(_DA_(d),*i,*j,*k); } //----------------------------------------------------------------------------- mreal *mgl_data_data(HMDT dat) { return dat->a; } diff --git a/src/data_io.cpp b/src/data_io.cpp index f4d0046..2f87f5e 100644 --- a/src/data_io.cpp +++ b/src/data_io.cpp @@ -17,11 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include -#include -#include -#include #ifndef WIN32 #include @@ -62,7 +58,7 @@ void mglFromStr(HMDT d,char *buf,long NX,long NY,long NZ) // TODO: add multithre if(NX<1 || NY <1 || NZ<1) return; mgl_data_create(d, NX,NY,NZ); long nb = strlen(buf); - register long i=0, j=0, k=0; + register long i=0, j=0; while(j='a' && buf[j]<='z') - d->id[k++] = buf[j]; + d->id.push_back(buf[j]); j++; } } @@ -237,11 +233,7 @@ void mgl_data_rearrange(HMDT d, long mx,long my,long mz) void mgl_data_rearrange_(uintptr_t *d, int *mx, int *my, int *mz) { mgl_data_rearrange(_DT_,*mx,*my,*mz); } //----------------------------------------------------------------------------- -void mgl_data_set_id(HMDT d, const char *ids) -{ - d->NewId(); // clearing + be sure about correct length - if(ids) for(long i=0;inx && ids[i]!=0;i++) d->id[i]=ids[i]; -} +void mgl_data_set_id(HMDT d, const char *ids) { d->id = ids; } void mgl_data_set_id_(uintptr_t *d, const char *eq,int l) { char *s=new char[l+1]; memcpy(s,eq,l); s[l]=0; mgl_data_set_id(_DT_, s); delete []s; } @@ -302,7 +294,7 @@ int mgl_data_read(HMDT d, const char *fname) char *buf = mgl_read_gz(fp); nb = strlen(buf); gzclose(fp); - bool first=false,com=false; + bool first=false; register char ch; for(i=nb-1;i>=0;i--) if(buf[i]>' ') break; buf[i+1]=0; nb = i; // remove tailing spaces @@ -320,6 +312,7 @@ int mgl_data_read(HMDT d, const char *fname) if(ch=='#') while(!isn(buf[i]) && inx = mx>0 ? mx:1; d->ny = my>0 ? my:1; d->nz = mz>0 ? mz:1; - if(d->a && d->id) delete []d->id; - if(d->a && !d->link) delete []d->a; + if(d->a && !d->link) delete [](d->a); d->a = new mreal[d->nx*d->ny*d->nz]; - d->id = new char[d->nx]; d->link=false; + d->id.clear(); d->link=false; memset(d->a,0,d->nx*d->ny*d->nz*sizeof(mreal)); - memset(d->id,0,d->nx*sizeof(char)); } void mgl_data_create_(uintptr_t *d, int *nx,int *ny,int *nz) { mgl_data_create(_DT_,*nx,*ny,*nz); } @@ -359,10 +352,9 @@ void mgl_data_create_(uintptr_t *d, int *nx,int *ny,int *nz) void mgl_data_link(HMDT d, mreal *A, long mx,long my,long mz) { if(!A) return; - if(d->id && d->a) delete []d->id; - if(!d->link && d->a) delete []d->a; + if(!d->link && d->a) delete [](d->a); d->nx = mx>0 ? mx:1; d->ny = my>0 ? my:1; d->nz = mz>0 ? mz:1; - d->link=true; d->NewId(); + d->link=true; d->a=A; d->NewId(); } void mgl_data_link_(uintptr_t *d, mreal *A, int *nx,int *ny,int *nz) { mgl_data_link(_DT_,A,*nx,*ny,*nz); } @@ -390,7 +382,7 @@ int mgl_data_read_mat(HMDT d, const char *fname, long dim) char *buf = mgl_read_gz(fp); long nb = strlen(buf); gzclose(fp); - register long j=0; + register long j=0,i,l; while(j' ') j++; + while(buf[j]!='\n' && j' ') j++; } else if(dim==2) { sscanf(buf+j,"%ld%ld",&nx,&ny); - while(buf[j]>' ' && j' ' && j' ' && !first) first=true; + if(first && (ch==' ' || ch=='\t' || ch==',') && b[i+1]>' ') nx++; + } + } } else if(dim==3) { sscanf(buf+j,"%ld%ld%ld",&nx,&ny,&nz); - while(buf[j]>' ' && j' ' && j' ' && j' ' && j' ' && jGetNN(); @@ -436,9 +446,9 @@ float mgl_data_max(HCDT d) { v = d->vthr(i); if(!mgl_isnan(v)) m = m>v ? m:v; } return m; } -float mgl_data_max_(uintptr_t *d) { return mgl_data_max(_DT_); } +mreal mgl_data_max_(uintptr_t *d) { return mgl_data_max(_DT_); } //----------------------------------------------------------------------------- -float mgl_data_min(HCDT d) +mreal mgl_data_min(HCDT d) { register mreal m=1e10, v; register long nn=d->GetNN(); @@ -449,9 +459,9 @@ float mgl_data_min(HCDT d) { v = d->vthr(i); if(!mgl_isnan(v)) m = mGetNx(), ny=d->GetNy(), nn=d->GetNN(); @@ -463,11 +473,11 @@ float mgl_data_max_int(HCDT d, long *i, long *j, long *k) } return m; } -float mgl_data_max_int_(uintptr_t *d, int *i, int *j, int *k) -{ long ii,jj,kk; float res=mgl_data_max_int(_DT_,&ii,&jj,&kk); +mreal mgl_data_max_int_(uintptr_t *d, int *i, int *j, int *k) +{ long ii,jj,kk; mreal res=mgl_data_max_int(_DT_,&ii,&jj,&kk); *i=ii; *j=jj; *k=kk; return res; } //----------------------------------------------------------------------------- -float mgl_data_min_int(HCDT d, long *i, long *j, long *k) +mreal mgl_data_min_int(HCDT d, long *i, long *j, long *k) { register mreal m=1e10, v; long nx=d->GetNx(), ny=d->GetNy(), nn=d->GetNN(); @@ -479,11 +489,11 @@ float mgl_data_min_int(HCDT d, long *i, long *j, long *k) } return m; } -float mgl_data_min_int_(uintptr_t *d, int *i, int *j, int *k) -{ long ii,jj,kk; float res=mgl_data_min_int(_DT_,&ii,&jj,&kk); +mreal mgl_data_min_int_(uintptr_t *d, int *i, int *j, int *k) +{ long ii,jj,kk; mreal res=mgl_data_min_int(_DT_,&ii,&jj,&kk); *i=ii; *j=jj; *k=kk; return res; } //----------------------------------------------------------------------------- -float mgl_data_max_real(HCDT d, mreal *x, mreal *y, mreal *z) +mreal mgl_data_max_real(HCDT d, mreal *x, mreal *y, mreal *z) { long im=-1,jm=-1,km=-1; long nx=d->GetNx(), ny=d->GetNy(), nz=d->GetNz(); @@ -514,10 +524,10 @@ float mgl_data_max_real(HCDT d, mreal *x, mreal *y, mreal *z) } return m; } -float mgl_data_max_real_(uintptr_t *d, mreal *x, mreal *y, mreal *z) +mreal mgl_data_max_real_(uintptr_t *d, mreal *x, mreal *y, mreal *z) { return mgl_data_max_real(_DT_,x,y,z); } //----------------------------------------------------------------------------- -float mgl_data_min_real(HCDT d, mreal *x, mreal *y, mreal *z) +mreal mgl_data_min_real(HCDT d, mreal *x, mreal *y, mreal *z) { long im=-1,jm=-1,km=-1; long nx=d->GetNx(), ny=d->GetNy(), nz=d->GetNz(); @@ -548,7 +558,7 @@ float mgl_data_min_real(HCDT d, mreal *x, mreal *y, mreal *z) } return m; } -float mgl_data_min_real_(uintptr_t *d, mreal *x, mreal *y, mreal *z) +mreal mgl_data_min_real_(uintptr_t *d, mreal *x, mreal *y, mreal *z) { return mgl_data_min_real(_DT_,x,y,z); } //----------------------------------------------------------------------------- void *mgl_fill_x(void *par) @@ -565,7 +575,7 @@ void *mgl_fill_x(void *par) } return 0; } -void mgl_data_fill(HMDT d, float x1,float x2,char dir) +void mgl_data_fill(HMDT d, mreal x1,mreal x2,char dir) { if(mgl_isnan(x2)) x2=x1; if(dir<'x' || dir>'z') dir='x'; @@ -576,10 +586,10 @@ void mgl_data_fill(HMDT d, float x1,float x2,char dir) if(dir=='z') b[1] *= d->nz>1 ? 1./(d->nz-1):0; mglStartThread(mgl_fill_x,0,d->nx*d->ny*d->nz,d->a,b,0,par,0,0,0,&dir); } -void mgl_data_fill_(uintptr_t *d, float *x1,float *x2,const char *dir,int) +void mgl_data_fill_(uintptr_t *d, mreal *x1,mreal *x2,const char *dir,int) { mgl_data_fill(_DT_,*x1,*x2,*dir); } //----------------------------------------------------------------------------- -void mgl_data_norm(HMDT d, float v1,float v2,long sym,long dim) +void mgl_data_norm(HMDT d, mreal v1,mreal v2,long sym,long dim) { long i,s,nn=d->nx*d->ny*d->nz; mreal a1=1e20,a2=-1e20,v,*a=d->a; @@ -600,7 +610,7 @@ void mgl_data_norm(HMDT d, float v1,float v2,long sym,long dim) for(i=s;ia[i1+nx*(j1+ny*k1)]; b[i+kx*(j+ky*k)] = s/dx*dy*dz; } - if(!d->link) delete []d->a; + if(!d->link) delete [](d->a); d->a=b; d->nx = kx; d->ny = ky; d->nz = kz; d->NewId(); d->link=false; } void mgl_data_squeeze_(uintptr_t *d, int *rx,int *ry,int *rz,int *smooth) diff --git a/src/data_new.cpp b/src/data_new.cpp index 126dbb8..74cc59a 100644 --- a/src/data_new.cpp +++ b/src/data_new.cpp @@ -17,11 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include -#include -#include - #include "mgl2/data.h" #if MGL_HAVE_GSL @@ -217,7 +213,7 @@ HMDT mgl_data_column(HCDT dat, const char *eq) mglFormula f(eq); mglData *r=new mglData(ny,nz); const mglData *d=dynamic_cast(dat); - if(d) mglStartThread(mgl_column,0,ny*nz,r->a,d->a,0,&nx,&f,0,0,d->id); + if(d) mglStartThread(mgl_column,0,ny*nz,r->a,d->a,0,&nx,&f,0,0,d->id.c_str()); return r; } uintptr_t mgl_data_column_(uintptr_t *d, const char *eq,int l) @@ -239,7 +235,7 @@ void *mgl_resize(void *par) } return 0; } -HMDT mgl_data_resize_box(HCDT dat, long mx,long my,long mz, float x1,float x2, float y1,float y2, float z1,float z2) +HMDT mgl_data_resize_box(HCDT dat, long mx,long my,long mz, mreal x1,mreal x2, mreal y1,mreal y2, mreal z1,mreal z2) { // NOTE: only for mglData (for speeding up) mx = mx<1 ? 1:mx; my = my<1 ? 1:my; mz = mz<1 ? 1:mz; mglData *r=new mglData(mx,my,mz); @@ -258,7 +254,7 @@ HMDT mgl_data_resize(HCDT d, long mx,long my,long mz) { return mgl_data_resize_box(d, mx,my,mz,0,1,0,1,0,1); } uintptr_t mgl_data_resize_(uintptr_t *d, int *mx,int *my,int *mz) { return uintptr_t(mgl_data_resize(_DT_,*mx,*my,*mz)); } -uintptr_t mgl_data_resize_box_(uintptr_t *d, int *mx,int *my,int *mz, float *x1,float *x2, float *y1,float *y2, float *z1,float *z2) +uintptr_t mgl_data_resize_box_(uintptr_t *d, int *mx,int *my,int *mz, mreal *x1,mreal *x2, mreal *y1,mreal *y2, mreal *z1,mreal *z2) { return uintptr_t(mgl_data_resize_box(_DT_,*mx,*my,*mz,*x1,*x2,*y1,*y2,*z1,*z2)); } //----------------------------------------------------------------------------- void *mgl_combine(void *par) @@ -838,7 +834,7 @@ void mgl_data_cosfft(HMDT d, const char *dir) k = i*nx; memset(b,0,4*nx*sizeof(double)); b[0] = b[2*nx] = a[k]; for(j=1;j1) @@ -851,7 +847,7 @@ void mgl_data_cosfft(HMDT d, const char *dir) memset(b,0,4*ny*sizeof(double)); b[0] = b[2*ny] = a[i+nx*ny*k]; for(j=1;j1) @@ -864,7 +860,7 @@ void mgl_data_cosfft(HMDT d, const char *dir) memset(b,0,4*nz*sizeof(double)); b[0] = b[2*nx] = a[i]; for(j=1;j1) @@ -909,7 +905,7 @@ void mgl_data_sinfft(HMDT d, const char *dir) memset(b,0,4*ny*sizeof(double)); b[0] = a[i+nx*ny*k]; b[2*ny] = -a[i+nx*ny*k]; for(j=1;j1) @@ -922,7 +918,7 @@ void mgl_data_sinfft(HMDT d, const char *dir) memset(b,0,4*nz*sizeof(double)); b[0] = a[i]; b[2*nx] = -a[i]; for(j=1;jGetNx()*ph->GetNy()*ph->GetNz() || !tr || tr[0]==0) return (new mglData); mglData re(nx,ny,nz), im(nx,ny,nz); - for(long i=0;i(am); + const mglData *dp=dynamic_cast(ph); + if(da && dp) for(long i=0;ia[i]*cos(dp->a[i]); + im.a[i] = da->a[i]*sin(dp->a[i]); } + else for(long i=0;ivthr(i)*cos(ph->vthr(i)); im.a[i] = am->vthr(i)*sin(ph->vthr(i)); } return mgl_transform(&re, &im, tr); @@ -1037,7 +1038,7 @@ void mgl_data_mul_dat(HMDT d, HCDT a) d->a[i+nx*(j+ny*k)] *= a->v(i,j,k); } //----------------------------------------------------------------------------- -void mgl_data_mul_num(HMDT d, float a) +void mgl_data_mul_num(HMDT d, mreal a) { long n=1, nx=d->nx, ny=d->ny, nz=d->nz; mreal aa=a; mglStartThread(mgl_eqmul,0,nx*ny*nz,d->a,&aa,0,&n); @@ -1069,7 +1070,7 @@ void mgl_data_div_dat(HMDT d, HCDT a) d->a[i+nx*(j+ny*k)] /= a->v(i,j,k); } //----------------------------------------------------------------------------- -void mgl_data_div_num(HMDT d, float a) +void mgl_data_div_num(HMDT d, mreal a) { long n=1, nx=d->nx, ny=d->ny, nz=d->nz; mreal aa=a; mglStartThread(mgl_eqdiv,0,nx*ny*nz,d->a,&aa,0,&n); @@ -1101,7 +1102,7 @@ void mgl_data_add_dat(HMDT d, HCDT a) d->a[i+nx*(j+ny*k)] += a->v(i,j,k); } //----------------------------------------------------------------------------- -void mgl_data_add_num(HMDT d, float a) +void mgl_data_add_num(HMDT d, mreal a) { long n=1, nx=d->nx, ny=d->ny, nz=d->nz; mreal aa=a; mglStartThread(mgl_eqadd,0,nx*ny*nz,d->a,&aa,0,&n); @@ -1133,7 +1134,7 @@ void mgl_data_sub_dat(HMDT d, HCDT a) d->a[i+nx*(j+ny*k)] -= a->v(i,j,k); } //----------------------------------------------------------------------------- -void mgl_data_sub_num(HMDT d, float a) +void mgl_data_sub_num(HMDT d, mreal a) { long n=1, nx=d->nx, ny=d->ny, nz=d->nz; mreal aa=a; mglStartThread(mgl_eqsub,0,nx*ny*nz,d->a,&aa,0,&n); @@ -1143,15 +1144,16 @@ void mgl_data_mul_dat_(uintptr_t *d, uintptr_t *b) { mgl_data_mul_dat(_DT_, _DA_ void mgl_data_div_dat_(uintptr_t *d, uintptr_t *b) { mgl_data_div_dat(_DT_, _DA_(b)); } void mgl_data_add_dat_(uintptr_t *d, uintptr_t *b) { mgl_data_add_dat(_DT_, _DA_(b)); } void mgl_data_sub_dat_(uintptr_t *d, uintptr_t *b) { mgl_data_sub_dat(_DT_, _DA_(b)); } -void mgl_data_mul_num_(uintptr_t *d, float *b) { mgl_data_mul_num(_DT_, *b); } -void mgl_data_div_num_(uintptr_t *d, float *b) { mgl_data_div_num(_DT_, *b); } -void mgl_data_add_num_(uintptr_t *d, float *b) { mgl_data_add_num(_DT_, *b); } -void mgl_data_sub_num_(uintptr_t *d, float *b) { mgl_data_sub_num(_DT_, *b); } +void mgl_data_mul_num_(uintptr_t *d, mreal *b) { mgl_data_mul_num(_DT_, *b); } +void mgl_data_div_num_(uintptr_t *d, mreal *b) { mgl_data_div_num(_DT_, *b); } +void mgl_data_add_num_(uintptr_t *d, mreal *b) { mgl_data_add_num(_DT_, *b); } +void mgl_data_sub_num_(uintptr_t *d, mreal *b) { mgl_data_sub_num(_DT_, *b); } //----------------------------------------------------------------------------- void mgl_hist_p(mglThreadD *t,mreal *a) { register long i,j,n=t[0].p[0]; mreal *b; + memset(a,0,n*sizeof(mreal)); for(i=0;in, n = t->p[0]; mreal *b=new mreal[n], *v=(mreal *)t->v; + memset(b,0,n*sizeof(mreal)); const mreal *a=t->b, *c=t->c; for(i=t->id;in, n = t->p[0]; long ns=t->p[1], nx=t->p[2], ny=t->p[3], nz=t->p[4]; mreal *b=new mreal[n], *v=(mreal *)t->v, f,w=1, x,y,z, d=1./ns; + memset(b,0,n*sizeof(mreal)); const mreal *a=t->b, *c=t->c; bool sp = n>0; for(i=t->id;ia = b; return 0; } -HMDT mgl_data_hist(HCDT dat, long n, float v1, float v2, long nsub) +HMDT mgl_data_hist(HCDT dat, long n, mreal v1, mreal v2, long nsub) { mglData *b=new mglData; // NOTE: For mglData only! const mglData *d = dynamic_cast(dat); @@ -1206,7 +1210,7 @@ HMDT mgl_data_hist(HCDT dat, long n, float v1, float v2, long nsub) return b; } //----------------------------------------------------------------------------- -HMDT mgl_data_hist_w(HCDT dat, HCDT weight, long n, float v1, float v2, long nsub) +HMDT mgl_data_hist_w(HCDT dat, HCDT weight, long n, mreal v1, mreal v2, long nsub) { mglData *b=new mglData; // NOTE: For mglData only! const mglData *d = dynamic_cast(dat); @@ -1222,9 +1226,9 @@ HMDT mgl_data_hist_w(HCDT dat, HCDT weight, long n, float v1, float v2, long nsu return b; } //----------------------------------------------------------------------------- -uintptr_t mgl_data_hist_(uintptr_t *d, int *n, float *v1, float *v2, int *nsub) +uintptr_t mgl_data_hist_(uintptr_t *d, int *n, mreal *v1, mreal *v2, int *nsub) { return uintptr_t(mgl_data_hist(_DT_,*n,*v1,*v2,*nsub)); } -uintptr_t mgl_data_hist_w_(uintptr_t *d, uintptr_t *w, int *n, float *v1, float *v2, int *nsub) +uintptr_t mgl_data_hist_w_(uintptr_t *d, uintptr_t *w, int *n, mreal *v1, mreal *v2, int *nsub) { return uintptr_t(mgl_data_hist_w(_DT_,_DA_(w),*n,*v1,*v2,*nsub)); } //----------------------------------------------------------------------------- mreal mglLinear(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mreal z) @@ -1235,7 +1239,7 @@ mreal mglLinear(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mre mreal b=0,dx,dy,dz,b1,b0; if(x<0 || y<0 || z<0 || x>nx-1 || y>ny-1 || z>nz-1) return 0; - if(nz>1 && z!=long(z)) // 3d interpolation + if(nz>1 && z!=floor(z)) // 3d interpolation { kx=long(x); ky=long(y); kz=long(z); dx = x-kx; dy = y-ky; dz = z-kz; @@ -1248,7 +1252,7 @@ mreal mglLinear(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mre dy*(1-dx)*a[i0+nx] + dx*dy*a[i0+nx+1]; b = b0 + dz*(b1-b0); } - else if(ny>1 && y!=long(y)) // 2d interpolation + else if(ny>1 && y!=floor(y)) // 2d interpolation { kx=long(x); ky=long(y); dx = x-kx; dy=y-ky; @@ -1256,7 +1260,7 @@ mreal mglLinear(const mreal *a, long nx, long ny, long nz, mreal x, mreal y, mre b = a[i0]*(1-dx-dy+dx*dy) + dx*(1-dy)*a[i0+1] + dy*(1-dx)*a[i0+nx] + dx*dy*a[i0+nx+1]; } - else if(nx>1 && x!=long(x)) // 1d interpolation + else if(nx>1 && x!=floor(x)) // 1d interpolation { kx = long(x); b = a[kx] + (x-kx)*(a[kx+1]-a[kx]); diff --git a/src/data_op.cpp b/src/data_op.cpp deleted file mode 100644 index 4e1808e..0000000 --- a/src/data_op.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/*************************************************************************** - * data_op.cpp is part of Math Graphic Library - * Copyright (C) 2007 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. * - ***************************************************************************/ -#include -#include -#include -#include - -#include "mgl2/data.h" -//----------------------------------------------------------------------------- diff --git a/src/data_png.cpp b/src/data_png.cpp index 74f79d5..d4351a7 100644 --- a/src/data_png.cpp +++ b/src/data_png.cpp @@ -17,10 +17,10 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include -#include #include "mgl2/data.h" +#if MGL_HAVE_PNG +#include +#endif //----------------------------------------------------------------------------- long mgl_col_dif(unsigned char *c1,unsigned char *c2,bool sum) { @@ -64,8 +64,9 @@ unsigned char *mgl_create_scheme(const char *scheme,long &num) return c; } //----------------------------------------------------------------------------- -void mgl_data_import(HMDT d, const char *fname, const char *scheme,float v1,float v2) +void mgl_data_import(HMDT d, const char *fname, const char *scheme,mreal v1,mreal v2) { +#if MGL_HAVE_PNG if(v1>=v2) return; long num=0; FILE *fp = fopen(fname, "rb"); @@ -106,19 +107,24 @@ void mgl_data_import(HMDT d, const char *fname, const char *scheme,float v1,floa delete []c; png_destroy_read_struct(&png_ptr, &info_ptr,&end_info); fclose(fp); +#endif } //----------------------------------------------------------------------------- -void mgl_data_export(HCDT dd, const char *fname, const char *scheme,float v1,float v2,long ns) +void mgl_data_export(HCDT dd, const char *fname, const char *scheme,mreal v1,mreal v2,long ns) { +#if MGL_HAVE_PNG register long i,j,k; long nx=dd->GetNx(), ny=dd->GetNy(), nz=dd->GetNz(); + const mglData *md = dynamic_cast(dd); mreal vv; if(v1>v2) return; if(ns<0 || ns>=nz) ns=0; if(v1==v2) { v1 = 1e20; v2=-1e20; - for(i=0;ia[i]; if(vvv2) v2=vv; } + else for(i=0;ivthr(i); if(vvv2) v2=vv; } } if(v1==v2) return; @@ -129,7 +135,13 @@ void mgl_data_export(HCDT dd, const char *fname, const char *scheme,float v1,flo unsigned char **p = (unsigned char **)malloc(ny*sizeof(unsigned char *)); unsigned char *d = (unsigned char *)malloc(3*nx*ny*sizeof(unsigned char)); for(i=0;ia[j+nx*(i+ny*nz)]-v1)/(v2-v1)); + if(k<0) k=0; if(k>=num) k=num-1; + memcpy(d+3*(j+i*nx),c+3*k,3*sizeof(unsigned char)); + } + else for(i=0;iv(j,i,ns)-v1)/(v2-v1)); if(k<0) k=0; if(k>=num) k=num-1; @@ -154,16 +166,17 @@ void mgl_data_export(HCDT dd, const char *fname, const char *scheme,float v1,flo png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); free(p); free(d); +#endif } //----------------------------------------------------------------------------- -void mgl_data_export_(uintptr_t *d, const char *fname, const char *scheme,float *v1,float *v2,int *ns,int l,int n) +void mgl_data_export_(uintptr_t *d, const char *fname, const char *scheme,mreal *v1,mreal *v2,int *ns,int l,int n) { char *s=new char[l+1]; memcpy(s,fname,l); s[l]=0; char *f=new char[n+1]; memcpy(f,scheme,n); f[n]=0; mgl_data_export(_DT_,s,f,*v1,*v2,*ns); delete []s; delete []f; } -void mgl_data_import_(uintptr_t *d, const char *fname, const char *scheme,float *v1,float *v2,int l,int n) +void mgl_data_import_(uintptr_t *d, const char *fname, const char *scheme,mreal *v1,mreal *v2,int l,int n) { char *s=new char[l+1]; memcpy(s,fname,l); s[l]=0; char *f=new char[n+1]; memcpy(f,scheme,n); f[n]=0; diff --git a/src/eval.cpp b/src/eval.cpp index 8942c9e..ca89c53 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -17,11 +17,8 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include -#include #include -#include #include "mgl2/eval.h" @@ -137,7 +134,7 @@ bool mglCheck(char *str,int n); int mglFindInText(char *str,const char *lst); //----------------------------------------------------------------------------- #if MGL_HAVE_GSL -gsl_rng *mgl_rng=0; +gsl_rng *mgl_rng=0; // TODO: should be deleted by gsl_rng_free() but I don't know where :( #endif void mgl_srnd(long seed) { @@ -399,7 +396,7 @@ mglFormula::mglFormula(const char *string) mreal mglFormula::Calc(mreal x,mreal y,mreal t,mreal u) const { Error=0; - mreal a1[MGL_VS]; memset(a1,0,MGL_VS*sizeof(float)); + mreal a1[MGL_VS]; memset(a1,0,MGL_VS*sizeof(mreal)); a1['a'-'a'] = a1['c'-'a'] = a1['u'-'a'] = u; a1['x'-'a'] = a1['r'-'a'] = x; a1['y'-'a'] = a1['n'-'a'] = a1['v'-'a'] = y; @@ -412,7 +409,7 @@ mreal mglFormula::Calc(mreal x,mreal y,mreal t,mreal u) const mreal mglFormula::Calc(mreal x,mreal y,mreal t,mreal u,mreal v,mreal w) const { Error=0; - mreal a1[MGL_VS]; memset(a1,0,MGL_VS*sizeof(float)); + mreal a1[MGL_VS]; memset(a1,0,MGL_VS*sizeof(mreal)); a1['c'-'a'] = a1['w'-'a'] = w; a1['b'-'a'] = a1['v'-'a'] = v; a1['a'-'a'] = a1['u'-'a'] = u; @@ -435,7 +432,7 @@ mreal mglFormula::Calc(const mreal var[MGL_VS]) const mreal mglFormula::CalcD(char diff,mreal x,mreal y,mreal t,mreal u) const { Error=0; - mreal a1[MGL_VS]; memset(a1,0,MGL_VS*sizeof(float)); + mreal a1[MGL_VS]; memset(a1,0,MGL_VS*sizeof(mreal)); a1['a'-'a'] = a1['c'-'a'] = a1['u'-'a'] = u; a1['x'-'a'] = a1['r'-'a'] = x; a1['y'-'a'] = a1['n'-'a'] = a1['v'-'a'] = y; @@ -448,7 +445,7 @@ mreal mglFormula::CalcD(char diff,mreal x,mreal y,mreal t,mreal u) const mreal mglFormula::CalcD(char diff,mreal x,mreal y,mreal t,mreal u,mreal v,mreal w) const { Error=0; - mreal a1[MGL_VS]; memset(a1,0,MGL_VS*sizeof(float)); + mreal a1[MGL_VS]; memset(a1,0,MGL_VS*sizeof(mreal)); a1['c'-'a'] = a1['w'-'a'] = w; a1['b'-'a'] = a1['v'-'a'] = v; a1['a'-'a'] = a1['u'-'a'] = u; @@ -495,9 +492,9 @@ double arg(double a,double b) { return atan2(b,a); } double mgz1(double) {return 0;} double mgz2(double,double) {return 0;} #ifdef WIN32 -double asinh(double x) { return log(x+sqrt(x*x+1)); } -double acosh(double x) { return x>1 ? log(x+sqrt(x*x-1)) : NAN; } -double atanh(double x) { return fabs(x)<1 ? log((1+x)/(1-x))/2 : NAN; } +double asinh(double x) { return log(x+sqrt(x*x+1.)); } +double acosh(double x) { return x>1 ? log(x+sqrt(x*x-1.)) : NAN; } +double atanh(double x) { return fabs(x)<1 ? log((1.+x)/(1.-x))/2 : NAN; } #endif //----------------------------------------------------------------------------- typedef double (*func_1)(double); @@ -505,7 +502,7 @@ typedef double (*func_2)(double, double); // evaluation of embedded (included) expressions mreal mglFormula::CalcIn(const mreal *a1) const { - float z2[22] = {3,3,3,3,0,3,3,0,0,0,0,0,NAN,0 + mreal z2[22] = {3,3,3,3,0,3,3,0,0,0,0,0,NAN,0 #if MGL_HAVE_GSL ,3,NAN, 3,NAN, 0,0,3,1 #else @@ -591,18 +588,18 @@ double llg1(double a,double b) {return 1/(a*log(b));} double llg2(double a,double b) {return -log(a)/(b*log(b)*log(b));} double cos_d(double a) {return -sin(a);} double tan_d(double a) {return 1./(cos(a)*cos(a));} -double asin_d(double a) {return 1./sqrt(1-a*a);} -double acos_d(double a) {return -1./sqrt(1-a*a);} -double atan_d(double a) {return 1./(1+a*a);} +double asin_d(double a) {return 1./sqrt(1.-a*a);} +double acos_d(double a) {return -1./sqrt(1.-a*a);} +double atan_d(double a) {return 1./(1.+a*a);} double tanh_d(double a) {return 1./(cosh(a)*cosh(a));} -double atanh_d(double a){return 1./(1-a*a);} -double asinh_d(double a){return 1./sqrt(1+a*a);} -double acosh_d(double a){return 1./sqrt(a*a-1);} +double atanh_d(double a){return 1./(1.-a*a);} +double asinh_d(double a){return 1./sqrt(1.+a*a);} +double acosh_d(double a){return 1./sqrt(a*a-1.);} double sqrt_d(double a) {return 0.5/sqrt(a);} double log10_d(double a){return M_LN10/a;} -double log_d(double a) {return 1/a;} +double log_d(double a) {return 1./a;} double erf_d(double a) {return 2*exp(-a*a)/sqrt(M_PI);} -double dilog_d(double a){return log(a)/(1-a);} +double dilog_d(double a){return log(a)/(1.-a);} double ei_d(double a) {return exp(a)/a;} double si_d(double a) {return a?sin(a)/a:1;} double ci_d(double a) {return cos(a)/a;} @@ -615,12 +612,12 @@ double gslJnuD(double a,double b) {return 0.5*(gsl_sf_bessel_Jnu(a-1,b)-gsl_sf_b double gslYnuD(double a,double b) {return 0.5*(gsl_sf_bessel_Ynu(a-1,b)-gsl_sf_bessel_Ynu(a+1,b));} double gslKnuD(double a,double b) {return -(a*gsl_sf_bessel_Knu(a,b)/b +gsl_sf_bessel_Knu(a-1,b));} double gslInuD(double a,double b) {return -(a*gsl_sf_bessel_Inu(a,b)/b -gsl_sf_bessel_Inu(a-1,b));} -double gslEllE1(double a,double b) {return sqrt(1-sin(a)*sin(a)*b);} -double gslEllE2(double a,double b) {return (gsl_sf_ellint_E(a,b,GSL_PREC_SINGLE) - gsl_sf_ellint_F(a,b,GSL_PREC_SINGLE))/(2*b);} -double gslEllF1(double a,double b) {return 1./sqrt(1-sin(a)*sin(a)*b);} -double gslEllF2(double a,double b) {return (gsl_sf_ellint_E(a,b,GSL_PREC_SINGLE) - gsl_sf_ellint_F(a,b,GSL_PREC_SINGLE)*(1-b))/(2*b*(1-b)) - sin(2*a)/(sqrt(1-sin(a)*sin(a)*b)*2*(1-b));} -double gslE_d(double a) {return (gsl_sf_ellint_Ecomp(a,GSL_PREC_SINGLE) - gsl_sf_ellint_Kcomp(a,GSL_PREC_SINGLE))/(2*a);} -double gslK_d(double a) {return (gsl_sf_ellint_Ecomp(a,GSL_PREC_SINGLE) - (1-a)*gsl_sf_ellint_Kcomp(a,GSL_PREC_SINGLE))/(2*a*(1-a));} +double gslEllE1(double a,double b) {return sqrt(1.-sin(a)*sin(a)*b);} +double gslEllE2(double a,double b) {return (gsl_sf_ellint_E(a,b,GSL_PREC_SINGLE) - gsl_sf_ellint_F(a,b,GSL_PREC_SINGLE))/(2.*b);} +double gslEllF1(double a,double b) {return 1./sqrt(1.-sin(a)*sin(a)*b);} +double gslEllF2(double a,double b) {return (gsl_sf_ellint_E(a,b,GSL_PREC_SINGLE) - gsl_sf_ellint_F(a,b,GSL_PREC_SINGLE)*(1.-b))/(2*b*(1.-b)) - sin(2.*a)/(sqrt(1.-sin(a)*sin(a)*b)*2.*(1.-b));} +double gslE_d(double a) {return (gsl_sf_ellint_Ecomp(a,GSL_PREC_SINGLE) - gsl_sf_ellint_Kcomp(a,GSL_PREC_SINGLE))/(2.*a);} +double gslK_d(double a) {return (gsl_sf_ellint_Ecomp(a,GSL_PREC_SINGLE) - (1.-a)*gsl_sf_ellint_Kcomp(a,GSL_PREC_SINGLE))/(2.*a*(1.-a));} double gamma_d(double a) {return gsl_sf_psi(a)*gsl_sf_gamma(a);} #endif //----------------------------------------------------------------------------- @@ -651,7 +648,6 @@ mreal mglFormula::CalcDIn(int id, const mreal *a1) const mgz1,mgz1,mgz1,mgz1,mgz1,mgz1,mgz1,mgz1,mgz1,mgz1,mgz1 #endif }; -// if(Error) return 0; if(KodCalcIn(a1), d = Left->CalcDIn(id,a1); diff --git a/src/evalc.cpp b/src/evalc.cpp index ca2d613..66defaa 100644 --- a/src/evalc.cpp +++ b/src/evalc.cpp @@ -17,17 +17,19 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include -#include -#include #include "mgl2/evalc.h" #include "mgl2/addon.h" -#include "mgl2/data.h" #if MGL_HAVE_GSL #include #endif //----------------------------------------------------------------------------- +extern "C"{ +void mgl_srnd(long seed); +double mgl_rnd(); +double mgl_ipow(double x,int n); +} +//----------------------------------------------------------------------------- // ��������� ��� ������������� ��������� enum{ EQ_NUM=0, // a variable substitution @@ -136,7 +138,7 @@ mglFormulaC::mglFormulaC(const char *string) { Kod=EQ_A; Res = str[0]-'a'; } else if(!strcmp(str,"rnd")) Kod=EQ_RND; else if(!strcmp(str,"pi")) Res=M_PI; - else if(str[0]=='i') Res = dual(0,atof(str+1)); + else if(str[0]=='i') Res = dual(0,str[1]>' '?atof(str+1):1); else Res=atof(str); // ��� ����� } else diff --git a/src/evalp.cpp b/src/evalp.cpp index 68648ed..0206a00 100644 --- a/src/evalp.cpp +++ b/src/evalp.cpp @@ -17,10 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include -#include -#include #include "mgl2/parser.h" #if MGL_HAVE_GSL #include @@ -208,6 +205,13 @@ mglData mglFormulaCalc(const wchar_t *string, mglParser *arg) else res = mglApplyOper(Buf,Buf+n+1,arg, div); delete []str; return res; } + n=mglFindInText(str,"@"); // high priority -- combine + if(n>=0) + { + wcscpy(Buf,str); Buf[n]=0; + const mglData &a = mglFormulaCalc(Buf,arg), &b = mglFormulaCalc(Buf+n+1,arg); + delete []str; return a.Combine(b); + } n=mglFindInText(str,"^"); // highest priority -- power if(n>=0) { @@ -260,7 +264,7 @@ mglData mglFormulaCalc(const wchar_t *string, mglParser *arg) else if(!wcscmp(p,L"wa")) { d.Momentum('a',x,y); v=y; } else if(!wcscmp(p,L"sa")) { d.Momentum('a',x,y,z,k);v=z; } else if(!wcscmp(p,L"ka")) { d.Momentum('a',x,y,z,k);v=k; } - // if this is valid suffix when finish parsing (it can be float number) + // if this is valid suffix when finish parsing (it can be mreal number) if(!mgl_isnan(v)) { res.a[0] = v; delete []str; return res; } } for(n=0;n='A' && str[k]<='Z') ? str[k]+'a'-'A' : str[k]; } //----------------------------------------------------------------------------- diff --git a/src/exec.cpp b/src/exec.cpp index 9d00f59..9e8d962 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -17,8 +17,6 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include #ifdef WIN32 #include #include @@ -271,6 +269,9 @@ int mgls_beam(mglGraph *gr, long , mglArg *a, int k[10], const char *) if(k[0]==1 && k[1]==1 && k[2]==1 && k[3]==1 && k[4]==3) gr->Beam(*(a[0].d),*(a[1].d),*(a[2].d),*(a[3].d),a[4].v, k[5]==2? a[5].s.c_str():"",k[6]==3?iint(a[6].v):0, iint(k[7]==3?a[7].v:3)); + if(k[0]==3 && k[1]==1 && k[2]==1 && k[3]==1 && k[4]==1 && k[5]==3) + gr->Beam(a[0].v,*(a[1].d),*(a[2].d),*(a[3].d),*(a[4].d),a[5].v, + k[6]==2? a[6].s.c_str():"",k[7]==3?iint(a[7].v):0); else return 1; return 0; } @@ -1492,7 +1493,7 @@ int mgls_read(mglGraph *gr, long n, mglArg *a, int k[10], const char *) else if(n==2) rr=a[0].d->Read(a[1].s.c_str()); else rr=a[0].d->Read(a[1].s.c_str(), k[2]==3?iint(a[2].v):1, k[3]==3?iint(a[3].v):1, k[4]==3?iint(a[4].v):1); - if(!rr) gr->SetWarn(mglWarnFile); + if(!rr) gr->SetWarn(mglWarnFile,"Read"); return 0; } void mglc_read(wchar_t out[1024], long n, mglArg *a, int k[10], const char *) @@ -1508,7 +1509,7 @@ int mgls_readmat(mglGraph *gr, long , mglArg *a, int k[10], const char *) bool rr=true; if(k[0]!=1 || k[1]!=2) return 1; else rr=a[0].d->ReadMat(a[1].s.c_str(), k[2]==3?iint(a[2].v):2); - if(!rr) gr->SetWarn(mglWarnFile); + if(!rr) gr->SetWarn(mglWarnFile,"ReadMat"); return 0; } void mglc_readmat(wchar_t out[1024], long , mglArg *a, int k[10], const char *) @@ -2021,7 +2022,7 @@ void mglc_surf3a(wchar_t out[1024], long , mglArg *a, int k[10], const char *opt int mgls_subplot(mglGraph *gr, long , mglArg *a, int k[10], const char *) { if(k[0]==3 && k[1]==3 && k[2]==3) - gr->SubPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v), k[3]==2?a[3].s.c_str():"<>_^", k[4]==3?a[3].v:0, k[5]==3?a[4].v:0); + gr->SubPlot(iint(a[0].v), iint(a[1].v), iint(a[2].v), k[3]==2?a[3].s.c_str():"<>_^", k[4]==3?a[4].v:0, k[5]==3?a[5].v:0); else return 1; return 0; } @@ -2686,13 +2687,15 @@ int mgls_info(mglGraph *gr, long , mglArg *a, int k[10], const char *) { if(k[0]==1) gr->SetWarn(-1,a[0].d->PrintInfo()); else if(k[0]==2) gr->SetWarn(-1,a[0].s.c_str()); - else return 1; + else + { char buf[128]; sprintf(buf,"value = %g",a[0].v); gr->SetWarn(-1,buf); } return 0; } void mglc_info(wchar_t out[1024], long , mglArg *a, int k[10], const char *) { if(k[0]==1) mglprintf(out,1024,L"gr->SetWarn(-1,%s.PrintInfo());", a[0].s.c_str()); if(k[0]==2) mglprintf(out,1024,L"gr->SetWarn(-1,\"%s\");",a[0].s.c_str()); + else mglprintf(out,1024,L"gr->SetWarn(-1,\"value = %g\");",a[0].v); } //----------------------------------------------------------------------------- int mgls_integrate(mglGraph *, long , mglArg *a, int k[10], const char *) @@ -2923,7 +2926,7 @@ void mglc_var(wchar_t out[1024], long , mglArg *a, int k[10], const char *) int mgls_chdir(mglGraph *gr, long , mglArg *a, int k[10], const char *) { if(k[0]==2) - { int r=chdir(a[0].s.c_str()); if(r) gr->SetWarn(mglWarnFile); } + { int r=chdir(a[0].s.c_str()); if(r) gr->SetWarn(mglWarnFile,"chdir"); } else return 1; return 0; } @@ -3171,7 +3174,7 @@ int mgls_fgets(mglGraph *gr, long , mglArg *a, int k[10], const char *) if((k[0]==3 && k[1]==3 && k[2]==3 && k[3]==2) || (k[0]==3 && k[1]==3 && k[2]==2)) { int i, j=k[2]==3?1:0, n = (k[j+3]==3?iint(a[j+3].v):0); - float vv = k[2]==3 ? a[2].v:0; + mreal vv = k[2]==3 ? a[2].v:0; fp = fopen(a[j+2].s.c_str(),"rt"); if(!fp) { @@ -3499,21 +3502,34 @@ void mglc_roll(wchar_t out[1024], long , mglArg *a, int k[10], const char *) a[0].s.c_str(), a[1].s.c_str()[0], iint(a[2].v)); } //----------------------------------------------------------------------------- +int mgls_datagrid(mglGraph *gr, long , mglArg *a, int k[10], const char *opt) +{ + if(k[0]==1 && k[1]==1 && k[2]==1 && k[3]==1) + gr->DataGrid(*(a[0].d), *(a[1].d), *(a[2].d), *(a[3].d), opt); + else return 1; + return 0; +} +void mglc_datagrid(wchar_t out[1024], long , mglArg *a, int k[10], const char *opt) +{ + if(k[0]==1 && k[1]==1 && k[2]==1 && k[3]==1) + mglprintf(out,1024,L"gr->DataGrid(%s, %s, %s, %s, \"%s\");",a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str(), a[3].s.c_str(),opt?opt:""); +} +//----------------------------------------------------------------------------- int mgls_triangulate(mglGraph *, long , mglArg *a, int k[10], const char *) { if(k[0]==1 && k[1]==1 && k[2]==1 && k[3]==1) - *(a[0].d) = mglTriangulation(*(a[1].d), *(a[2].d), *(a[3].d), k[4]==3?a[4].v:0); + *(a[0].d) = mglTriangulation(*(a[1].d), *(a[2].d), *(a[3].d)); else if(k[0]==1 && k[1]==1 && k[2]==1) - *(a[0].d) = mglTriangulation(*(a[1].d), *(a[2].d), k[3]==3?a[3].v:0); + *(a[0].d) = mglTriangulation(*(a[1].d), *(a[2].d)); else return 1; return 0; } void mglc_triangulate(wchar_t out[1024], long , mglArg *a, int k[10], const char *) { if(k[0]==1 && k[1]==1 && k[2]==1 && k[3]==1) - mglprintf(out,1024,L"%s = mglTriangulation(%s, %s, %s, %g);",a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str(), a[3].s.c_str(), k[4]==3?a[4].v:0); + mglprintf(out,1024,L"%s = mglTriangulation(%s, %s, %s);",a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str(), a[3].s.c_str()); else if(k[0]==1 && k[1]==1 && k[2]==1) - mglprintf(out,1024,L"%s = mglTriangulation(%s, %s, %g);",a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str(), k[3]==3?a[3].v:0); + mglprintf(out,1024,L"%s = mglTriangulation(%s, %s);",a[0].s.c_str(), a[1].s.c_str(), a[2].s.c_str()); } //----------------------------------------------------------------------------- mglCommand mgls_base_cmd[] = { @@ -3549,7 +3565,7 @@ mglCommand mgls_base_cmd[] = { {"colorbar","Draw colorbar","colorbar ['fmt' pos]|Vdat ['fmt' pos]|'sch' pos x y w h|Vdat 'sch' pos x y w h", mgls_colorbar, mglc_colorbar,1}, {"column","Get data column filled by formula on column ids","column Res Dat 'eq'", mgls_column, mglc_column,4}, {"columnplot","Set position of plot inside cell of column", "columnplot num ind [d]", mgls_columnplot, mglc_columnplot,5}, - {"combine", "Direct multiplication of arrays", "combine Res Adat Bdat", mgls_combine, mglc_combine,3}, + {"combine", "Direct multiplication of arrays", "combine Res Adat Bdat", mgls_combine, mglc_combine,4}, {"cone","Draw cone","cone x1 y1 z1 x2 y2 z2 r1 [r2 'fmt' edge]", mgls_cone, mglc_cone,1}, {"cones","Draw cones for 1D data","cones Ydat ['fmt' above]|Xdat Ydat ['fmt' above]|Xdat Ydat Zdat ['fmt' above]", mgls_cones, mglc_cones,0}, {"cont","Draw contour lines","cont Zdat ['fmt' num zpos]|Vdat Zdat ['fmt' zpos]|Xdat Ydat Zdat ['fmt' num zpos]|Vdat Xdat Ydat Zdat ['fmt' zpos]", mgls_cont, mglc_cont,0}, @@ -3574,6 +3590,7 @@ mglCommand mgls_base_cmd[] = { {"cumsum","Cumulative summation","cumsum Dat 'dir'", mgls_cumsum, mglc_cumsum,3}, {"curve","Draw curve","curve x1 y1 dx1 dy1 x2 y2 dx2 dy2 ['fmt']|x1 y1 z1 dx1 dy1 dz1 x2 y2 z2 dx2 dy2 dz2 ['fmt']", mgls_curve, mglc_curve,1}, {"cut","Setup plot points cutting","cut val|x1 y1 z1 x2 y2 z2|'cond'", mgls_cut, mglc_cut,2}, + {"datagrid","Fill data by triangulated values","datagrid Var Xdat Ydat Zdat", mgls_datagrid, mglc_datagrid,3}, {"datas","Print list of data names in HDF file","datas 'fname'", mgls_datas, mglc_datas,3}, {"defchr","Define parameter as character","defchr $N val", 0, 0, 6}, {"define","Define constant or parameter","define $N sth | Var val", 0, 0, 6}, diff --git a/src/export.cpp b/src/export.cpp index bb10541..66ce793 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -17,17 +17,16 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include -#include #include -#include #include -#include #include "mgl2/canvas.h" #include "mgl2/canvas_cf.h" +#if MGL_HAVE_PNG +#include +#endif + #if MGL_HAVE_JPEG extern "C" { #include @@ -36,6 +35,7 @@ extern "C" { //----------------------------------------------------------------------------- int mgl_pnga_save(const char *fname, int w, int h, unsigned char **p) { +#if MGL_HAVE_PNG FILE *fp = fopen(fname, "wb"); if (!fp) return 1; @@ -59,10 +59,14 @@ int mgl_pnga_save(const char *fname, int w, int h, unsigned char **p) png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); return 0; +#else + return 1; +#endif } //----------------------------------------------------------------------------- int mgl_png_save(const char *fname, int w, int h, unsigned char **p) { +#if MGL_HAVE_PNG FILE *fp = fopen(fname, "wb"); if (!fp) return 1; @@ -86,6 +90,9 @@ int mgl_png_save(const char *fname, int w, int h, unsigned char **p) png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); return 0; +#else + return 1; +#endif } //----------------------------------------------------------------------------- int mgl_bmp_save(const char *fname, int w, int h, unsigned char **p) @@ -481,6 +488,10 @@ void mgl_write_frame_(uintptr_t *gr, const char *fname,const char *descr,int l,i char *f=new char[n+1]; memcpy(f,descr,n); f[n]=0; mgl_write_frame(_GR_,s,f); delete []s; delete []f;} //----------------------------------------------------------------------------- +#ifdef WIN32 +#include +#include +#endif void mgl_show_image(HMGL gr, const char *viewer, int keep) { char fname[128], *cmd = new char [128]; @@ -488,7 +499,7 @@ void mgl_show_image(HMGL gr, const char *viewer, int keep) mgl_write_png_solid(gr,fname,"MathGL ShowImage file"); if(!viewer || !viewer[0]) viewer = MGL_DEF_VIEWER; - #ifdef WIN32 +#ifdef WIN32 if(keep) { sprintf(cmd,"%s %s &", viewer,fname); @@ -497,7 +508,7 @@ void mgl_show_image(HMGL gr, const char *viewer, int keep) sprintf(cmd,"del %s", fname); } else sprintf(cmd,"%s %s; del %s", viewer,fname,fname); - #else +#else if(keep) { sprintf(cmd,"%s %s &", viewer,fname); @@ -506,7 +517,7 @@ void mgl_show_image(HMGL gr, const char *viewer, int keep) sprintf(cmd,"rm %s", fname); } else sprintf(cmd,"%s %s; rm %s", viewer,fname,fname); - #endif +#endif if(system(cmd)==-1) printf("Error to call external viewer\n"); delete []cmd; } diff --git a/src/export_2d.cpp b/src/export_2d.cpp index 963a769..a92db4a 100644 --- a/src/export_2d.cpp +++ b/src/export_2d.cpp @@ -19,15 +19,15 @@ ***************************************************************************/ #include "mgl2/canvas.h" #include "mgl2/canvas_cf.h" -#include #include -#include +#include +#include #undef _GR_ #define _GR_ ((mglCanvas *)(*gr)) #define _Gr_ ((mglCanvas *)(gr)) void mgl_printf(void *fp, bool gz, const char *str, ...); //----------------------------------------------------------------------------- -char *mgl_get_dash(unsigned short d, float w) +char *mgl_get_dash(unsigned short d, mreal w) { static char s[64],b[4]; if(d==0xffff) { strcpy(s,""); return s; } @@ -48,7 +48,7 @@ char *mgl_get_dash(unsigned short d, float w) return s; } //----------------------------------------------------------------------------- -bool mgl_is_same(HMGL gr, const mglPrim &pr,float wp,mglColor cp,int st) +bool mgl_is_same(HMGL gr, const mglPrim &pr,mreal wp,mglColor cp,int st) { if(abs(pr.type)!=1) return false; if(pr.w>=1 && wp!=pr.w) return false; @@ -58,69 +58,70 @@ bool mgl_is_same(HMGL gr, const mglPrim &pr,float wp,mglColor cp,int st) return (cp==c); } //----------------------------------------------------------------------------- -void put_line(HMGL gr, void *fp, bool gz, long i, float wp, mglColor cp,int st, const char *ifmt, const char *nfmt, bool neg, float fc) +void put_line(HMGL gr, void *fp, bool gz, long i, mreal wp, mglColor cp,int st, const char *ifmt, const char *nfmt, bool neg, mreal fc) { - const mglPnt pp = gr->GetPnt(gr->GetPrm(i).n1); - float x0=pp.x, y0=pp.y; + register long n1=gr->GetPrm(i).n1, n2=gr->GetPrm(i).n2; + if(n1<0 || n2<0) return; + const mglPnt &pp1 = gr->GetPnt(n1), &pp2 = gr->GetPnt(n2); + mreal x0=pp1.x, y0=pp1.y; bool ok=true; - register long k = i,j; // first point - while(ok) + register long j; // first point + std::vector ids; + while(ok) // try to find starting point { for(ok=false,j=i+1;jGetPrmNum();j++) { mglPrim &q = gr->GetPrm(j); if(q.type>1) break; - if(mgl_is_same(gr, q,wp,cp,st) && q.type==1) // previous point + if(mgl_is_same(gr, q,wp,cp,st) && q.type==1 && q.n1>=0 && q.n2>=0) // previous point { - const mglPnt p1 = gr->GetPnt(q.n1); - const mglPnt p2 = gr->GetPnt(q.n2); + const mglPnt &p1 = gr->GetPnt(q.n1); + const mglPnt &p2 = gr->GetPnt(q.n2); if(p2.x==x0 && p2.y==y0) { - k=j; ok=true; q.type = -2; - x0 = p1.x; y0=p1.y; + ok = true; ids.push_back(q.n1); + x0 = p1.x; y0 = p1.y; q.type = -1; } else if(p1.x==x0 && p1.y==y0) { - k=j; ok=true; q.type = -2; - x0 = p2.x; y0=p2.y; + ok = true; ids.push_back(q.n2); + x0 = p2.x; y0 = p2.y; q.type = -1; } } } } - for(j=i;jGetPrmNum();j++) + std::reverse(ids.begin(),ids.end()); + ids.push_back(n1); ids.push_back(n2); + x0 = pp2.x; y0 = pp2.y; ok = true; + while(ok) // try to find starting point { - mglPrim &q = gr->GetPrm(j); - if(q.type==-2) q.type = 1; - } - mgl_printf(fp, gz, ifmt,fc*x0,(neg?_Gr_->GetHeight()-y0:y0)*fc); ok=true; - long m=1; - while(ok) - { - for(ok=false,j=i;jGetPrmNum();j++) + for(ok=false,j=i+1;jGetPrmNum();j++) { mglPrim &q = gr->GetPrm(j); if(q.type>1) break; - if(mgl_is_same(gr,q,wp,cp,st) && q.type==1) + if(mgl_is_same(gr, q,wp,cp,st) && q.type==1 && q.n1>=0 && q.n2>=0) // next point { - const mglPnt p1 = gr->GetPnt(q.n1); - const mglPnt p2 = gr->GetPnt(q.n2); - if(p1.x==x0 && p1.y==y0) + const mglPnt &p1 = gr->GetPnt(q.n1); + const mglPnt &p2 = gr->GetPnt(q.n2); + if(p2.x==x0 && p2.y==y0) { - k=j; q.type = -1; x0 = p2.x; y0=p2.y; - mgl_printf(fp, gz, nfmt,fc*x0,(neg?_Gr_->GetHeight()-y0:y0)*fc); - if(m>10) { m=0; mgl_printf(fp, gz, "\n"); } - ok=true; m++; + ok = true; ids.push_back(q.n1); + x0 = p1.x; y0 = p1.y; q.type = -1; } - else if(p2.x==x0 && p2.y==y0) + else if(p1.x==x0 && p1.y==y0) { - k=j; q.type = -1; x0 = p1.x; y0=p1.y; - mgl_printf(fp, gz, nfmt,fc*x0,(neg?_Gr_->GetHeight()-y0:y0)*fc); - if(m>10) { m=0; mgl_printf(fp, gz, "\n"); } - ok=true; m++; + ok = true; ids.push_back(q.n2); + x0 = p2.x; y0 = p2.y; q.type = -1; } } } } + for(j=0;jGetPnt(ids[j]); + x0 = p.x; y0 = p.y; + mgl_printf(fp, gz, j>0?nfmt:ifmt,fc*x0,(neg?_Gr_->GetHeight()-y0:y0)*fc); + } } //----------------------------------------------------------------------------- //put_desc(fp,"%c%c%c_%04x {", "np %d %d mt %d %d ll %d %d ll cp fill\n", @@ -251,7 +252,7 @@ void mgl_write_eps(HMGL gr, const char *fname,const char *descr) // write definition for all glyphs put_desc(gr,fp,gz,"/%c%c_%04x { np\n", "\t%d %d mt ", "%d %d ll ", "cp\n", "} def\n"); // write primitives - float wp=-1; + mreal wp=-1; mglColor cp; int st=0; char str[256]=""; @@ -265,7 +266,7 @@ void mgl_write_eps(HMGL gr, const char *fname,const char *descr) if(q.type==0) // mark { - float x0 = p1.x,y0 = p1.y; + mreal x0 = p1.x,y0 = p1.y; sprintf(str,"1 lw %.2g %.2g %.2g rgb ", cp.r,cp.g,cp.b); wp=1; if(q.s!=gr->mark_size()/gr->FontFactor()) @@ -329,12 +330,12 @@ void mgl_write_eps(HMGL gr, const char *fname,const char *descr) } else if(q.type==4) // glyph { - float ss = q.s/2, xx = p1.u, yy = p1.v, zz = p1.w; + mreal ss = q.s/2, xx = p1.u, yy = p1.v, zz = p1.w; mgl_printf(fp, gz, "gsave\t%g %g translate %g %g scale %g rotate %s\n", p1.x, p1.y, ss, ss, -q.w, str); if(q.n3&8) // this is "line" { - float dy = 0.004,f=fabs(zz); + mreal dy = 0.004,f=fabs(zz); mgl_printf(fp, gz, "np %g %g mt %g %g ll %g %g ll %g %g ll cp ", xx,yy+dy, xx+f,yy+dy, xx+f,yy-dy, xx,yy-dy); } @@ -382,7 +383,7 @@ void mgl_write_svg(HMGL gr, const char *fname,const char *descr) // currentColor -> inherit ??? mgl_printf(fp, gz, "\n"); // write primitives - float wp=-1; + mreal wp=-1; register long i; int st=0; mglColor cp; @@ -395,7 +396,7 @@ void mgl_write_svg(HMGL gr, const char *fname,const char *descr) const mglPnt p1=gr->GetPnt(q.n1); if(q.type==0) { - float x=p1.x,y=p1.y,s=0.4*gr->FontFactor()*q.s; + mreal x=p1.x,y=hh-p1.y,s=0.4*gr->FontFactor()*q.s; if(!strchr("xsSoO",q.n4)) s *= 1.1; wp = 1; if(strchr("SDVTLR",q.n4)) @@ -405,11 +406,13 @@ void mgl_write_svg(HMGL gr, const char *fname,const char *descr) switch(q.n4) { case 'P': - mgl_printf(fp, gz, "\n", x-s,y,x+s,y,x,y-s,x,y+s, x-s,y-s,x+s,y-s,x+s,y+s,x-s,y+s,x-s,y-s); break; + mgl_printf(fp, gz, "\n", + x-s,y,x+s,y,x,y-s,x,y+s, x-s,y-s,x+s,y-s,x+s,y+s,x-s,y+s,x-s,y-s); break; case '+': mgl_printf(fp, gz, "\n", x-s,y,x+s,y,x,y-s,x,y+s); break; case 'X': - mgl_printf(fp, gz, "\n", x-s,y-s,x+s,y+s,x+s,y-s,x-s,y+s, x-s,y-s,x+s,y-s,x+s,y+s,x-s,y+s,x-s,y-s); break; + mgl_printf(fp, gz, "\n", + x-s,y-s,x+s,y+s,x+s,y-s,x-s,y+s, x-s,y-s,x+s,y-s,x+s,y+s,x-s,y+s,x-s,y-s); break; case 'x': mgl_printf(fp, gz, "\n", x-s,y-s,x+s,y+s,x+s,y-s,x-s,y+s); break; case 's': @@ -420,10 +423,10 @@ void mgl_write_svg(HMGL gr, const char *fname,const char *descr) mgl_printf(fp, gz, "\n", x-s,y,x,y-s,x+s,y,x,y+s); break; case '^': case 'T': - mgl_printf(fp, gz, "\n", x-s,y+s/2,x+s,y+s/2,x,y-s); break; + mgl_printf(fp, gz, "\n", x-s,y-s/2,x+s,y-s/2,x,y+s); break; case 'v': case 'V': - mgl_printf(fp, gz, "\n", x-s,y-s/2,x+s,y-s/2,x,y+s); break; + mgl_printf(fp, gz, "\n", x-s,y+s/2,x+s,y+s/2,x,y-s); break; case '<': case 'L': mgl_printf(fp, gz, "\n", x+s/2,y+s,x+s/2,y-s,x-s,y); break; @@ -431,17 +434,21 @@ void mgl_write_svg(HMGL gr, const char *fname,const char *descr) case 'R': mgl_printf(fp, gz, "\n", x-s/2,y+s,x-s/2,y-s,x+s,y); break; case 'Y': - mgl_printf(fp, gz, "\n", x,y+s, x,y, x+s,y-s, x,y, x-s,y-s); break; + mgl_printf(fp, gz, "\n", x,y-s, x,y, x+s,y+s, x,y, x-s,y+s); break; case 'C': - mgl_printf(fp, gz, "\n\n", int(255*cp.r),int(255*cp.g),int(255*cp.b),x,y,x,y,s); break; + mgl_printf(fp, gz, "\n\n", + int(255*cp.r),int(255*cp.g),int(255*cp.b),x,y,x,y,s); break; case 'o': mgl_printf(fp, gz, "\n", x,y,s); break; case 'O': - mgl_printf(fp, gz, "\n", int(255*cp.r),int(255*cp.g),int(255*cp.b),x,y,s); break; + mgl_printf(fp, gz, "\n", + int(255*cp.r),int(255*cp.g),int(255*cp.b),x,y,s); break; case '*': - mgl_printf(fp, gz, "\n", x-s,y,x+s,y,x-0.6*s,y-0.8*s,x+0.6*s,y+0.8*s,x+0.6*s,y-0.8*s,x-0.6*s,y+0.8*s); break; + mgl_printf(fp, gz, "\n", + x-s,y,x+s,y,x-0.6*s,y-0.8*s,x+0.6*s,y+0.8*s,x+0.6*s,y-0.8*s,x-0.6*s,y+0.8*s); break; default: - mgl_printf(fp, gz, "\n", int(255*cp.r),int(255*cp.g),int(255*cp.b),x,y); break; + mgl_printf(fp, gz, "\n", + int(255*cp.r),int(255*cp.g),int(255*cp.b),x,y); break; } mgl_printf(fp, gz, "\n"); } @@ -473,7 +480,7 @@ void mgl_write_svg(HMGL gr, const char *fname,const char *descr) } else if(q.type==4) { - float ss = q.s/2, xx = p1.u, yy = p1.v, zz = p1.w; + mreal ss = q.s/2, xx = p1.u, yy = p1.v, zz = p1.w; if(q.n3&8) // this is "line" { mgl_printf(fp, gz, "", int(255*cp.r),int(255*cp.g),int(255*cp.b)); else mgl_printf(fp, gz, " fill=\"#%02x%02x%02x\">", int(255*cp.r),int(255*cp.g),int(255*cp.b)); - float dy = 0.004,f=fabs(zz); + mreal dy = 0.004,f=fabs(zz); mgl_printf(fp, gz, "\n", xx,yy+dy, xx+f,yy+dy, xx+f,yy-dy, xx,yy-dy); } else @@ -508,7 +515,7 @@ void mgl_write_svg_(uintptr_t *gr, const char *fname,const char *descr,int l,int mgl_write_svg(_GR_,s,d); delete []s; delete []d; } //----------------------------------------------------------------------------- /// Color names easely parsed by LaTeX -struct mglSVGName { const char *name; float r,g,b; }; +struct mglSVGName { const char *name; mreal r,g,b; }; mglSVGName mgl_names[]={{"AliceBlue",.94,.972,1}, {"Apricot", 0.984, 0.725, 0.51}, {"Aquamarine", 0, 0.71, 0.745}, @@ -743,7 +750,7 @@ mglSVGName mgl_names[]={{"AliceBlue",.94,.972,1}, const char *mglColorName(mglColor c) // return closest SVG color { register long i; - register float d, dm=10; + register mreal d, dm=10; const char *name=""; for(i=0;mgl_names[i].name[0];i++) { @@ -766,10 +773,10 @@ void mgl_write_tex(HMGL gr, const char *fname,const char *descr) if(!fp) { gr->SetWarn(mglWarnOpen,fname); return; } fprintf(fp, "%% Created by MathGL library\n%% Title: %s\n",descr?descr:fname); fprintf(fp, "\\input{mglcolors.tex}\n\\begin{tikzpicture}\n"); - float ms=0.4*gr->mark_size()/100; + mreal ms=0.4*gr->mark_size()/100; // write primitives - float wp=-1; + mreal wp=-1; register long i; int st=0; mglColor cp; @@ -830,7 +837,7 @@ void mgl_write_tex(HMGL gr, const char *fname,const char *descr) sprintf(cname,"mgl_%d",ii+6*(jj+6*kk)); // cname = mglColorName(cp); const mglPnt p1=gr->GetPnt(q.n1); - float x=p1.x/100,y=p1.y/100,s=0.4*gr->FontFactor()*q.s/100; + mreal x=p1.x/100,y=p1.y/100,s=0.4*gr->FontFactor()*q.s/100; if(q.type==0) { if(!strchr("xsSoO",q.n4)) s *= 1.1; @@ -889,7 +896,7 @@ void mgl_write_tex(HMGL gr, const char *fname,const char *descr) else if(q.type==6) // text { const mglText &t = gr->GetPtx(q.n3); - float ftet = mgl_isnan(p1.v)||mgl_isnan(p1.u) ? 0:-180*atan2(p1.v,p1.u)/M_PI; + mreal ftet = mgl_isnan(p1.v)||mgl_isnan(p1.u) ? 0:-180*atan2(p1.v,p1.u)/M_PI; int f,a; mglGetStyle(t.stl.c_str(), &f, &a); std::string ss=cname; if((a&3)==2) ss.append(",west"); if((a&3)==0) ss.append(",east"); diff --git a/src/export_3d.cpp b/src/export_3d.cpp index f0ffc02..3613476 100644 --- a/src/export_3d.cpp +++ b/src/export_3d.cpp @@ -17,9 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include -#include #include "mgl2/canvas.h" #include "mgl2/canvas_cf.h" #undef _GR_ @@ -72,9 +70,9 @@ void mglTexture::GetRGBA(unsigned char *f) const } }*/ //----------------------------------------------------------------------------- -void mgl_obj_prim(const mglPrim &q, const mglPnt &p, FILE *fp, float size) +void mgl_obj_prim(const mglPrim &q, const mglPnt &p, FILE *fp, mreal size) { - char type = q.n4; float ss=size*0.35; + char type = q.n4; mreal ss=size*0.35; register long i=q.n1+1,j; register long n1=q.n1+1,n2=q.n2+1,n3=q.n3+1,n4=q.n4+1; switch(q.type) @@ -464,7 +462,7 @@ void mgl_write_off_(uintptr_t *gr, const char *fname,const char *descr,int *colo char *d=new char[n+1]; memcpy(d,descr,n); d[n]=0; mgl_write_off(_GR_,s,d,*colored); delete []s; delete []d; } //----------------------------------------------------------------------------- -void mgl_write_idtf(HMGL gr, const char *fname,const char *descr) +void mgl_write_idtf(HMGL /*gr*/, const char */*fname*/,const char */*descr*/) { /*_Gr_->WriteIDTF(fname,descr);*/ } // TODO: Add idtf support later void mgl_write_idtf_(uintptr_t *gr, const char *fname,const char *descr,int l,int n) { char *s=new char[l+1]; memcpy(s,fname,l); s[l]=0; @@ -478,10 +476,10 @@ void mgl_write_idtf_(uintptr_t *gr, const char *fname,const char *descr,int l,in long n1,n2,n3,n4; ///< coordinates of corners int type; ///< primitive type (0-point, 1-line, 2-trig, 3-quad, 4-glyph, 6-text) int id; ///< object id - float z; ///< z-position - float s; ///< size (if applicable) or fscl - float w; ///< width (if applicable) or ftet - float p; + mreal z; ///< z-position + mreal s; ///< size (if applicable) or fscl + mreal w; ///< width (if applicable) or ftet + mreal p; };*/ bool mglCanvas::ExportMGLD(const char *fname, const char *descr) { @@ -489,7 +487,7 @@ bool mglCanvas::ExportMGLD(const char *fname, const char *descr) FILE *fp=fopen(fname,"wt"); if(!fp) return true; // NOTE: I'll save Ptx. So prim type=6 is useless,and no LaTeX - fprintf(fp,"MGLD %lu %lu %lu\n# %s\n", Pnt.size(), Prm.size(), Txt.size(), (descr && *descr) ? descr : fname); + fprintf(fp,"MGLD %lu %lu %lu\n# %s\n", (unsigned long)Pnt.size(), (unsigned long)Prm.size(), (unsigned long)Txt.size(), (descr && *descr) ? descr : fname); register size_t i; fprintf(fp,"# Vertexes: x y z c t ta u v w r g b a\n"); for(i=0;i /* if(q.type==0) // mark { - float x0 = p1.x,y0 = p1.y; + mreal x0 = p1.x,y0 = p1.y; sprintf(str,"1 lw %.2g %.2g %.2g rgb ", cp.r,cp.g,cp.b); wp=1; if(q.s!=gr->mark_size()/gr->FontFactor()) @@ -934,12 +932,12 @@ void mgl_x3d_prim(const mglPrim &q, const mglPnt &p, const long *pnt, void *fp,b } else if(q.type==4) // glyph { - float ss = q.s/2, xx = p1.u, yy = p1.v, zz = p1.w; + mreal ss = q.s/2, xx = p1.u, yy = p1.v, zz = p1.w; mgl_printf(fp, gz, "gsave\t%g %g translate %g %g scale %g rotate %s\n", p1.x, p1.y, ss, ss, -q.w, str); if(q.n3&8) // this is "line" { - float dy = 0.004,f=fabs(zz); + mreal dy = 0.004,f=fabs(zz); mgl_printf(fp, gz, "np %g %g mt %g %g ll %g %g ll %g %g ll cp ", xx,yy+dy, xx+f,yy+dy, xx+f,yy-dy, xx,yy-dy); } diff --git a/src/fit.cpp b/src/fit.cpp index f9f541b..9223b67 100644 --- a/src/fit.cpp +++ b/src/fit.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include #include "mgl2/fit.h" +#include "mgl2/prim.h" #include "mgl2/eval.h" #include "mgl2/data.h" @@ -30,6 +31,23 @@ int mglFitPnts=100; ///< Number of output points in fitting char mglFitRes[1024]; ///< Last fitted formula //----------------------------------------------------------------------------- +void mgl_puts_fit(HMGL gr, mreal x, mreal y, mreal z, const char *pre, const char *font, mreal size) +{ + long n = strlen(mglFitRes)+(pre?strlen(pre):0)+1; + char *buf = new char[n]; + if(pre) sprintf(buf,"%s%s",pre,mglFitRes); + else strcpy(buf,mglFitRes); + mgl_puts(gr,x,y,z,buf,font,size); + delete []buf; +} +void mgl_puts_fit_(uintptr_t* gr, mreal *x, mreal *y, mreal *z, const char *prefix, const char *font, mreal *size, int l, int n) +{ + char *s=new char[l+1]; memcpy(s,prefix,l); s[l]=0; + char *d=new char[n+1]; memcpy(d,font,n); d[n]=0; + mgl_puts_fit(_GR_, *x,*y,*z, s, d, *size); + delete []s; delete []d; +} +//----------------------------------------------------------------------------- /// Structure for keeping data and precompiled fitted formula struct mglFitData { @@ -209,12 +227,14 @@ HMDT mgl_fit_xys(HMGL gr, HCDT xx, HCDT yy, HCDT ss, const char *eq, const char { mglData *fit=new mglData; long m = yy->GetNx(); - if(xx->GetNx()!=m) { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } - if(m<2) { gr->SetWarn(mglWarnLow,"Fit[S]"); return fit; } + long nn = long(0.5+gr->SaveState(opt)); + if(xx->GetNx()!=m) + { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } + if(m<2) + { gr->SetWarn(mglWarnLow,"Fit[S]"); return fit; } if(ss->GetNx()*ss->GetNy()*ss->GetNz() != m*yy->GetNy()*yy->GetNz()) - { gr->SetWarn(mglWarnDim,"FitS"); return fit; } + { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } - long nn = long(0.5+gr->SaveState(opt)); if(nnGetNx(),n=zz->GetNy(); - if(xx->GetNx()!=m) { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } + long nn = long(0.5+gr->SaveState(opt)); + if(xx->GetNx()!=m) + { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } if(ss->GetNx()*ss->GetNy()*ss->GetNz() != m*n*zz->GetNz()) - { gr->SetWarn(mglWarnDim,"FitS"); return fit; } + { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } if(yy->GetNx()!=n && (xx->GetNy()!=n || yy->GetNx()!=m || yy->GetNy()!=n)) - { gr->SetWarn(mglWarnDim); return fit; } - if(m<2|| n<2) { gr->SetWarn(mglWarnLow,"Fit[S]"); return fit; } + { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } + if(m<2|| n<2) + { gr->SetWarn(mglWarnLow,"Fit[S]"); return fit; } - long nn = long(0.5+gr->SaveState(opt)); if(nnGetNx(), n=aa->GetNy(), l=aa->GetNz(); i = n*m*l; - if(m<2 || n<2 || l<2) { gr->SetWarn(mglWarnLow,"Fit[S]"); return fit; } - if(ss->GetNx()*ss->GetNy()*ss->GetNz() != i) { gr->SetWarn(mglWarnDim,"FitS"); return fit; } + long nn = long(0.5+gr->SaveState(opt)); + if(m<2 || n<2 || l<2) + { gr->SetWarn(mglWarnLow,"Fit[S]"); return fit; } + if(ss->GetNx()*ss->GetNy()*ss->GetNz() != i) + { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } bool both = xx->GetNx()*xx->GetNy()*xx->GetNz()==i && yy->GetNx()*yy->GetNy()*yy->GetNz()==i && zz->GetNx()*zz->GetNy()*zz->GetNz()==i; if(!(both || (xx->GetNx()==m && yy->GetNx()==n && zz->GetNx()==l))) { gr->SetWarn(mglWarnDim,"Fit[S]"); return fit; } - long nn = long(0.5+gr->SaveState(opt)); if(nnGetNx()*a->GetNy()*a->GetNz(); if(nn!=x->GetNx()*x->GetNy()*x->GetNz()) - { gr->SetWarn(mglWarnDim); return (new mglData); } + { gr->SetWarn(mglWarnDim,"Hist"); return (new mglData); } long n = long(0.5+gr->SaveState(opt)); if(n(x); + const mglData *da = dynamic_cast(a); + mreal vx = n/(gr->Max.x-gr->Min.x); + if(dx && da) for(i=0;ia[i]-gr->Min.x)*vx); + if(j1>=0 && j1a[j1] += da->a[i]; + } + else for(i=0;iStop) { delete res; return 0; } - j1 = long(n*(x->v(i)-gr->Min.x)/(gr->Max.x-gr->Min.x)); - if(j1>=0 && j1a[j1] += a->v(i); + j1 = long((x->vthr(i)-gr->Min.x)*vx); + if(j1>=0 && j1a[j1] += a->vthr(i); } gr->LoadState(); return res; } @@ -362,18 +394,27 @@ HMDT mgl_hist_xy(HMGL gr, HCDT x, HCDT y, HCDT a, const char *opt) { long nn=a->GetNx()*a->GetNy()*a->GetNz(); if(nn!=x->GetNx()*x->GetNy()*x->GetNz() || nn!=y->GetNx()*y->GetNy()*y->GetNz()) - { gr->SetWarn(mglWarnDim); return (new mglData); } + { gr->SetWarn(mglWarnDim,"Hist"); return (new mglData); } long n = long(0.5+gr->SaveState(opt)); if(n(x); + const mglData *dy = dynamic_cast(y); + const mglData *da = dynamic_cast(a); + mreal vx = n/(gr->Max.x-gr->Min.x); + mreal vy = n/(gr->Max.y-gr->Min.y); + if(dx && dy && da) for(i=0;ia[i]-gr->Min.x)*vx); + j2 = long((dy->a[i]-gr->Min.y)*vy); + if(j1>=0 && j1=0 && j2a[j1+n*j2] += da->a[i]; + } + else for(i=0;iStop) { delete res; return 0; } - j1 = long(n*(x->v(i)-gr->Min.x)/(gr->Max.x-gr->Min.x)); - j2 = long(n*(y->v(i)-gr->Min.y)/(gr->Max.y-gr->Min.y)); - if(j1>=0 && j1=0 && j2a[j1+n*j2] += a->v(i); + j1 = long((x->vthr(i)-gr->Min.x)*vx); + j2 = long((y->vthr(i)-gr->Min.y)*vy); + if(j1>=0 && j1=0 && j2a[j1+n*j2] += a->vthr(i); } gr->LoadState(); return res; } @@ -382,19 +423,32 @@ HMDT mgl_hist_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *opt) { long nn=a->GetNx()*a->GetNy()*a->GetNz(); if(nn!=x->GetNx()*x->GetNy()*x->GetNz() || nn!=y->GetNx()*y->GetNy()*y->GetNz() || nn!=z->GetNx()*z->GetNy()*z->GetNz()) - { gr->SetWarn(mglWarnDim); return (new mglData); } + { gr->SetWarn(mglWarnDim,"Hist"); return (new mglData); } long n = long(0.5+gr->SaveState(opt)); if(n(x); + const mglData *dy = dynamic_cast(y); + const mglData *dz = dynamic_cast(z); + const mglData *da = dynamic_cast(a); + mreal vx = n/(gr->Max.x-gr->Min.x), vy = n/(gr->Max.y-gr->Min.y), vz = n/(gr->Max.z-gr->Min.z); + if(dx && dy && dz && da) for(i=0;ia[i]-gr->Min.x)*vx); + j2 = long((dy->a[i]-gr->Min.y)*vy); + j3 = long((dz->a[i]-gr->Min.z)*vz); + if(j1>=0 && j1=0 && j2=0 && j3a[j1+n*(j2+n*j3)] += da->a[i]; + } + else for(i=0;iStop) { delete res; return 0; } - j1 = long(n*(x->v(i)-gr->Min.x)/(gr->Max.x-gr->Min.x)); - j2 = long(n*(y->v(i)-gr->Min.y)/(gr->Max.y-gr->Min.y)); - j3 = long(n*(z->v(i)-gr->Min.z)/(gr->Max.z-gr->Min.z)); + if(gr->Stop) { res->Create(1,1,1); return res; } + j1 = long((x->vthr(i)-gr->Min.x)*vx); + j2 = long((y->vthr(i)-gr->Min.y)*vy); + j3 = long((z->vthr(i)-gr->Min.z)*vz); if(j1>=0 && j1=0 && j2=0 && j3a[j1+n*(j2+n*j3)] += a->v(i); + res->a[j1+n*(j2+n*j3)] += a->vthr(i); } gr->LoadState(); return res; } diff --git a/src/font.cpp b/src/font.cpp index d20e14b..41aa7b5 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -17,17 +17,15 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include #include #include -#include -#ifdef WIN32 -#include -#else -#include -#endif +// #ifdef WIN32 +// #include +// #else +// #include +// #endif #include "mgl2/base.h" #include "mgl2/font.h" @@ -109,7 +107,7 @@ float mglFont::Width(const wchar_t *str,const char *how) const //----------------------------------------------------------------------------- float mglFont::Puts(const wchar_t *str,int font,int align, float col) const { - if(numg==0) return 0; + if(numg==0 || !str || *str==0) return 0; float ww=0,w=0,h = (align&4) ? 500./fact[0] : 0; size_t size = wcslen(str)+1,i,num=0; if(parse) @@ -158,7 +156,7 @@ float mglFont::Puts(const wchar_t *str,int font,int align, float col) const //----------------------------------------------------------------------------- float mglFont::Width(const wchar_t *str,int font) const { - if(numg==0) return 0; + if(numg==0 || !str || *str==0) return 0; float ww=0,w=0; unsigned size = wcslen(str)+1,i; if(parse) @@ -289,7 +287,7 @@ unsigned mglFont::Parse(const wchar_t *s) const void mglFont::Convert(const wchar_t *str, unsigned *res) const { register unsigned r,i,j,k,i0; - wchar_t s[128], ch; // TeX command and current char + wchar_t s[128]=L"", ch; // TeX command and current char for(i=j=0;str[i];i++) { ch = str[i]; @@ -745,8 +743,8 @@ mglFont::mglFont(const char *name, const char *path) parse = true; numg=0; gr=0; // if(this==&mglDefFont) Load(name, path); else Copy(&mglDefFont); if(this!=&mglDefFont) Copy(&mglDefFont); - if(this==&mglDefFont && (!name || name[0]==0)) Load(MGL_DEF_FONT_NAME,0); - else if(name && name[0]) Load(name, path); + else if(name && *name) Load(name, path); + else Load(MGL_DEF_FONT_NAME,0); } mglFont::~mglFont() { Clear(); } void mglFont::Restore() { Copy(&mglDefFont); } @@ -757,11 +755,11 @@ void mglFont::Clear() if(numg) { delete []id; free(Buf); numg = 0; - delete []width[0]; delete []width[1]; delete []width[2]; delete []width[3]; - delete []tr[0]; delete []tr[1]; delete []tr[2]; delete []tr[3]; - delete []ln[0]; delete []ln[1]; delete []ln[2]; delete []ln[3]; - delete []numt[0]; delete []numt[1]; delete []numt[2]; delete []numt[3]; - delete []numl[0]; delete []numl[1]; delete []numl[2]; delete []numl[3]; + delete [](width[0]); delete [](width[1]); delete [](width[2]); delete [](width[3]); + delete [](tr[0]); delete [](tr[1]); delete [](tr[2]); delete [](tr[3]); + delete [](ln[0]); delete [](ln[1]); delete [](ln[2]); delete [](ln[3]); + delete [](numt[0]); delete [](numt[1]); delete [](numt[2]); delete [](numt[3]); + delete [](numl[0]); delete [](numl[1]); delete [](numl[2]); delete [](numl[3]); } } //----------------------------------------------------------------------------- diff --git a/src/opengl.cpp b/src/opengl.cpp index 301b9a4..fb233aa 100644 --- a/src/opengl.cpp +++ b/src/opengl.cpp @@ -33,7 +33,7 @@ void mglCanvasGL::Finish(bool fast) glEnableClientState(GL_COLOR_ARRAY); int pdef=PDef; - float ss=pPos, ww=PenWidth; + mreal ss=pPos, ww=PenWidth; mglPrim p; for(unsigned long i=0;i7) { SetWarn(mglWarnLId); return; } + if(n<0 || n>7) { SetWarn(mglWarnLId,"AddLight"); return; } if(c.Valid()) { DifLight = c*br; @@ -141,7 +141,7 @@ void mglCanvasGL::LightScale() } } //----------------------------------------------------------------------------- -void mglCanvasGL::View(float TetX,float TetY,float TetZ) +void mglCanvasGL::View(mreal TetX,mreal TetY,mreal TetZ) { glMatrixMode(GL_PROJECTION);//GL_PROJECTION GL_VIEWPORT GL_MODELVIEW glRotated(TetX,1.,0.,0.); @@ -149,11 +149,11 @@ void mglCanvasGL::View(float TetX,float TetY,float TetZ) glRotated(TetZ,0.,0.,1.); } //----------------------------------------------------------------------------- -void mglCanvasGL::Fog(float d, float) +void mglCanvasGL::Fog(mreal d, mreal) { if(d>0) // TODO: Check fog to OpenGL mode { - float back[4]={BDef[0]/255.,BDef[1]/255.,BDef[2]/255.,BDef[3]/255.}; + float back[4]={BDef[0]/255.f,BDef[1]/255.f,BDef[2]/255.f,BDef[3]/255.f}; glFogf(GL_FOG_MODE,GL_EXP); glFogf(GL_FOG_DENSITY,5*d); glFogfv(GL_FOG_COLOR,back); @@ -179,7 +179,7 @@ void mglCanvasGL::Clf(mglColor Back) glTranslated(-0.5,-0.5,-0.5); } //----------------------------------------------------------------------------- -void mglCanvasGL::set_pen(unsigned style,float width) +void mglCanvasGL::set_pen(unsigned style,mreal width) { if(style==0) return; if(style!=0xffff) diff --git a/src/other.cpp b/src/other.cpp index 8725be3..ed19dd3 100644 --- a/src/other.cpp +++ b/src/other.cpp @@ -2,467 +2,499 @@ * other.cpp is part of Math Graphic Library * Copyright (C) 2007 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. * - ***************************************************************************/ + * 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. * + ***************************************************************************/ #include "mgl2/other.h" #include "mgl2/surf.h" #include "mgl2/cont.h" -#include "mgl2/eval.h" -#include "mgl2/data.h" -#include +#include "mgl2/eval.h" +#include "mgl2/data.h" +//----------------------------------------------------------------------------- +// +// DensX, DensY, DensZ series +// //----------------------------------------------------------------------------- -// -// DensX, DensY, DensZ series -// -//----------------------------------------------------------------------------- -void mgl_dens_x(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"DensX"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"DensX"); return; } - mglData xx,yy,zz,aa; +void mgl_dens_x(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"DensX"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"DensX"); return; } + mglData xx,yy,zz,aa; gr->SaveState(opt); - - if(l>1) - { - aa.Create(m,l); xx.Create(m,l); yy.Create(m,l); zz.Create(m,l); - float d = (n-1)*(sv - gr->Min.x)/(gr->Max.x - gr->Min.x); - k = long(d); d = d - k; - if(k>n-2) { k=n-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(k,i,j)*(1-d) + d*a->v(k+1,i,j); - a = &aa; - } - else - { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } - xx.Fill(sv, sv); - yy.Fill(gr->Min.y, gr->Max.y,'x'); - zz.Fill(gr->Min.z, gr->Max.z,'y'); - mgl_surfc_xy(gr,&xx,&yy,&zz,a,sch,0); -} -//----------------------------------------------------------------------------- -void mgl_dens_y(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"DensY"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"DensY"); return; } - mglData xx,yy,zz,aa; + + if(l>1) + { + aa.Create(m,l); xx.Create(m,l); yy.Create(m,l); zz.Create(m,l); + mreal d = (n-1)*(sv - gr->Min.x)/(gr->Max.x - gr->Min.x); + k = long(d); d = d - k; + if(k>n-2) { k=n-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+1+n*(i+m*j)]; + else for(j=0;jv(k,i,j)*(1-d) + d*a->v(k+1,i,j); + a = &aa; + } + else + { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } + xx.Fill(sv, sv); + yy.Fill(gr->Min.y, gr->Max.y,'x'); + zz.Fill(gr->Min.z, gr->Max.z,'y'); + mgl_surfc_xy(gr,&xx,&yy,&zz,a,sch,0); +} +//----------------------------------------------------------------------------- +void mgl_dens_y(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"DensY"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"DensY"); return; } + mglData xx,yy,zz,aa; gr->SaveState(opt); - - if(l>1) - { - aa.Create(n,l); xx.Create(n,l); yy.Create(n,l); zz.Create(n,l); - float d = (m-1)*(sv - gr->Min.y)/(gr->Max.y - gr->Min.y); - k = long(d); d = d - k; - if(k>m-2) { k=m-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(i,k,j)*(1-d) + d*a->v(i,k+1,j); - a = &aa; - } - else - { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } - yy.Fill(sv, sv); - xx.Fill(gr->Min.x, gr->Max.x,'x'); - zz.Fill(gr->Min.z, gr->Max.z,'y'); - mgl_surfc_xy(gr,&xx,&yy,&zz,a,sch,0); -} -//----------------------------------------------------------------------------- -void mgl_dens_z(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"DensZ"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"DensZ"); return; } - mglData xx,yy,zz,aa; + + if(l>1) + { + aa.Create(n,l); xx.Create(n,l); yy.Create(n,l); zz.Create(n,l); + mreal d = (m-1)*(sv - gr->Min.y)/(gr->Max.y - gr->Min.y); + k = long(d); d = d - k; + if(k>m-2) { k=m-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+n+n*(i+m*j)]; + else for(j=0;jv(i,k,j)*(1-d) + d*a->v(i,k+1,j); + a = &aa; + } + else + { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } + yy.Fill(sv, sv); + xx.Fill(gr->Min.x, gr->Max.x,'x'); + zz.Fill(gr->Min.z, gr->Max.z,'y'); + mgl_surfc_xy(gr,&xx,&yy,&zz,a,sch,0); +} +//----------------------------------------------------------------------------- +void mgl_dens_z(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"DensZ"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"DensZ"); return; } + mglData xx,yy,zz,aa; gr->SaveState(opt); - - xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); - if(l>1) - { - aa.Create(n,m); - float d = (l-1)*(sv - gr->Min.z)/(gr->Max.z - gr->Min.z); - k = long(d); d = d - k; - if(k>l-2) { k=l-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(i,j,k)*(1-d) + d*a->v(i,j,k+1); - a = &aa; - } - zz.Fill(sv, sv); - yy.Fill(gr->Min.y, gr->Max.y,'y'); - xx.Fill(gr->Min.x, gr->Max.x,'x'); - mgl_surfc_xy(gr,&xx,&yy,&zz,a,sch,0); -} -//----------------------------------------------------------------------------- -void mgl_dens_x_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + + xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); + if(l>1) + { + aa.Create(n,m); + mreal d = (l-1)*(sv - gr->Min.z)/(gr->Max.z - gr->Min.z); + k = long(d); d = d - k; + if(k>l-2) { k=l-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+n*m+n*(i+m*j)]; + else for(j=0;jv(i,j,k)*(1-d) + d*a->v(i,j,k+1); + a = &aa; + } + zz.Fill(sv, sv); + yy.Fill(gr->Min.y, gr->Max.y,'y'); + xx.Fill(gr->Min.x, gr->Max.x,'x'); + mgl_surfc_xy(gr,&xx,&yy,&zz,a,sch,0); +} +//----------------------------------------------------------------------------- +void mgl_dens_x_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_dens_x(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -void mgl_dens_y_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ - char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_dens_x(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +void mgl_dens_y_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ + char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_dens_y(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -void mgl_dens_z_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ - char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_dens_y(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +void mgl_dens_z_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ + char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_dens_z(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -// -// ContX, ContY, ContZ series -// -//----------------------------------------------------------------------------- -void mgl_cont_gen(HMGL gr, float val, HCDT a, HCDT x, HCDT y, HCDT z, float c, int text,long ak); -void mgl_cont_x_val(HMGL gr, HCDT v, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContX"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContX"); return; } + mgl_dens_z(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +// +// ContX, ContY, ContZ series +// +//----------------------------------------------------------------------------- +void mgl_cont_gen(HMGL gr, mreal val, HCDT a, HCDT x, HCDT y, HCDT z, mreal c, int text,long ak); +void mgl_cont_x_val(HMGL gr, HCDT v, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContX"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContX"); return; } gr->SaveState(opt); - static int cgid=1; gr->StartGroup("ContX",cgid++); - mglData xx,yy,zz,aa; - - bool text=(sch && strchr(sch,'t')); - long ss=gr->AddTexture(sch); - gr->SetPenPal(sch); - - if(l>1) - { - aa.Create(m,l); xx.Create(m,l); yy.Create(m,l); zz.Create(m,l); - float d = (n-1)*(sv - gr->Min.x)/(gr->Max.x - gr->Min.x); - k = long(d); d = d - k; - if(k>n-2) { k=n-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(k,i,j)*(1-d) + d*a->v(k+1,i,j); - a = &aa; - } - else - { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } - xx.Fill(sv, sv); - yy.Fill(gr->Min.y, gr->Max.y,'x'); - zz.Fill(gr->Min.z, gr->Max.z,'y'); - for(i=0;iGetNx();i++) - { - register float v0 = v->v(i); - mgl_cont_gen(gr,v0,a,&xx,&yy,&zz,gr->GetC(ss,v0),text,0); - } - gr->EndGroup(); -} -//----------------------------------------------------------------------------- -void mgl_cont_y_val(HMGL gr, HCDT v, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContY"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContY"); return; } + static int cgid=1; gr->StartGroup("ContX",cgid++); + mglData xx,yy,zz,aa; + + bool text=(sch && strchr(sch,'t')); + long ss=gr->AddTexture(sch); + gr->SetPenPal(sch); + + if(l>1) + { + aa.Create(m,l); xx.Create(m,l); yy.Create(m,l); zz.Create(m,l); + mreal d = (n-1)*(sv - gr->Min.x)/(gr->Max.x - gr->Min.x); + k = long(d); d = d - k; + if(k>n-2) { k=n-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+1+n*(i+m*j)]; + else for(j=0;jv(k,i,j)*(1-d) + d*a->v(k+1,i,j); + a = &aa; + } + else + { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } + xx.Fill(sv, sv); + yy.Fill(gr->Min.y, gr->Max.y,'x'); + zz.Fill(gr->Min.z, gr->Max.z,'y'); + for(i=0;iGetNx();i++) + { + register mreal v0 = v->v(i); + mgl_cont_gen(gr,v0,a,&xx,&yy,&zz,gr->GetC(ss,v0),text,0); + } + gr->EndGroup(); +} +//----------------------------------------------------------------------------- +void mgl_cont_y_val(HMGL gr, HCDT v, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContY"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContY"); return; } gr->SaveState(opt); - static int cgid=1; gr->StartGroup("ContY",cgid++); - mglData xx,yy,zz,aa; - - bool text=(sch && strchr(sch,'t')); - long ss=gr->AddTexture(sch); - gr->SetPenPal(sch); - - if(l>1) - { - aa.Create(n,l); xx.Create(n,l); yy.Create(n,l); zz.Create(n,l); - float d = (m-1)*(sv - gr->Min.y)/(gr->Max.y - gr->Min.y); - k = long(d); d = d - k; - if(k>m-2) { k=m-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(i,k,j)*(1-d) + d*a->v(i,k+1,j); - a = &aa; - } - else - { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } - yy.Fill(sv, sv); - xx.Fill(gr->Min.x, gr->Max.x,'x'); - zz.Fill(gr->Min.z, gr->Max.z,'y'); - for(i=0;iGetNx();i++) - { - register float v0 = v->v(i); - mgl_cont_gen(gr,v0,a,&xx,&yy,&zz,gr->GetC(ss,v0),text,0); - } - gr->EndGroup(); -} -//----------------------------------------------------------------------------- -void mgl_cont_z_val(HMGL gr, HCDT v, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContZ"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContZ"); return; } + static int cgid=1; gr->StartGroup("ContY",cgid++); + mglData xx,yy,zz,aa; + + bool text=(sch && strchr(sch,'t')); + long ss=gr->AddTexture(sch); + gr->SetPenPal(sch); + + if(l>1) + { + aa.Create(n,l); xx.Create(n,l); yy.Create(n,l); zz.Create(n,l); + mreal d = (m-1)*(sv - gr->Min.y)/(gr->Max.y - gr->Min.y); + k = long(d); d = d - k; + if(k>m-2) { k=m-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+n+n*(i+m*j)]; + else for(j=0;jv(i,k,j)*(1-d) + d*a->v(i,k+1,j); + a = &aa; + } + else + { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } + yy.Fill(sv, sv); + xx.Fill(gr->Min.x, gr->Max.x,'x'); + zz.Fill(gr->Min.z, gr->Max.z,'y'); + for(i=0;iGetNx();i++) + { + register mreal v0 = v->v(i); + mgl_cont_gen(gr,v0,a,&xx,&yy,&zz,gr->GetC(ss,v0),text,0); + } + gr->EndGroup(); +} +//----------------------------------------------------------------------------- +void mgl_cont_z_val(HMGL gr, HCDT v, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContZ"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContZ"); return; } gr->SaveState(opt); - static int cgid=1; gr->StartGroup("ContZ",cgid++); - mglData xx,yy,zz,aa; - - bool text=(sch && strchr(sch,'t')); - long ss=gr->AddTexture(sch); - gr->SetPenPal(sch); - - xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); - if(l>1) - { - aa.Create(n,m); - float d = (l-1)*(sv - gr->Min.z)/(gr->Max.z - gr->Min.z); - k = long(d); d = d - k; - if(k>l-2) { k=l-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(i,j,k)*(1-d) + d*a->v(i,j,k+1); - a = &aa; - } - zz.Fill(sv, sv); - yy.Fill(gr->Min.y, gr->Max.y,'y'); - xx.Fill(gr->Min.x, gr->Max.x,'x'); - for(i=0;iGetNx();i++) - { - register float v0 = v->v(i); - mgl_cont_gen(gr,v0,a,&xx,&yy,&zz,gr->GetC(ss,v0),text,0); - } - gr->EndGroup(); -} -//----------------------------------------------------------------------------- -void mgl_cont_x(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - float r = gr->SaveState(opt); - long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); - mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); - mgl_cont_x_val(gr,&v,a,sch,sv,0); -} -//----------------------------------------------------------------------------- -void mgl_cont_y(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - float r = gr->SaveState(opt); - long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); - mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); - mgl_cont_y_val(gr,&v,a,sch,sv,0); -} -//----------------------------------------------------------------------------- -void mgl_cont_z(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - float r = gr->SaveState(opt); - long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); - mglData v(Num); - for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*float(i+1)/(Num+1); - mgl_cont_z_val(gr,&v,a,sch,sv,0); -} -//----------------------------------------------------------------------------- -void mgl_cont_x_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + static int cgid=1; gr->StartGroup("ContZ",cgid++); + mglData xx,yy,zz,aa; + + bool text=(sch && strchr(sch,'t')); + long ss=gr->AddTexture(sch); + gr->SetPenPal(sch); + + xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); + if(l>1) + { + aa.Create(n,m); + mreal d = (l-1)*(sv - gr->Min.z)/(gr->Max.z - gr->Min.z); + k = long(d); d = d - k; + if(k>l-2) { k=l-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+n*m+n*(i+m*j)]; + else for(j=0;jv(i,j,k)*(1-d) + d*a->v(i,j,k+1); + a = &aa; + } + zz.Fill(sv, sv); + yy.Fill(gr->Min.y, gr->Max.y,'y'); + xx.Fill(gr->Min.x, gr->Max.x,'x'); + for(i=0;iGetNx();i++) + { + register mreal v0 = v->v(i); + mgl_cont_gen(gr,v0,a,&xx,&yy,&zz,gr->GetC(ss,v0),text,0); + } + gr->EndGroup(); +} +//----------------------------------------------------------------------------- +void mgl_cont_x(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + mreal r = gr->SaveState(opt); + long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); + mglData v(Num); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); + mgl_cont_x_val(gr,&v,a,sch,sv,0); + gr->LoadState(); +} +//----------------------------------------------------------------------------- +void mgl_cont_y(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + mreal r = gr->SaveState(opt); + long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); + mglData v(Num); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); + mgl_cont_y_val(gr,&v,a,sch,sv,0); + gr->LoadState(); +} +//----------------------------------------------------------------------------- +void mgl_cont_z(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + mreal r = gr->SaveState(opt); + long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); + mglData v(Num); + for(long i=0;iMin.c + (gr->Max.c-gr->Min.c)*mreal(i+1)/(Num+1); + mgl_cont_z_val(gr,&v,a,sch,sv,0); + gr->LoadState(); +} +//----------------------------------------------------------------------------- +void mgl_cont_x_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_cont_x(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -void mgl_cont_y_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_cont_x(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +void mgl_cont_y_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_cont_y(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -void mgl_cont_z_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_cont_y(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +void mgl_cont_z_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_cont_z(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -void mgl_cont_x_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_cont_z(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +void mgl_cont_x_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_cont_x_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -void mgl_cont_y_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_cont_x_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +void mgl_cont_y_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_cont_y_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -void mgl_cont_z_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_cont_y_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +void mgl_cont_z_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_cont_z_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s; } -//----------------------------------------------------------------------------- -// -// ContFX, ContFY, ContFZ series -// -//----------------------------------------------------------------------------- -void mgl_contf_gen(HMGL gr, float v1, float v2, HCDT a, HCDT x, HCDT y, HCDT z, float c, long ak); -void mgl_contf_x_val(HMGL gr, HCDT v, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContFX"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContFX"); return; } - gr->SaveState(opt); - static int cgid=1; gr->StartGroup("ContFX",cgid++); - mglData xx,yy,zz,aa; - long ss=gr->AddTexture(sch); - - if(l>1) - { - aa.Create(m,l); xx.Create(m,l); yy.Create(m,l); zz.Create(m,l); - float d = (n-1)*(sv - gr->Min.x)/(gr->Max.x - gr->Min.x); - k = long(d); d = d - k; - if(k>n-2) { k=n-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(k,i,j)*(1-d) + d*a->v(k+1,i,j); - a = &aa; - } - else - { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } - xx.Fill(sv, sv); - yy.Fill(gr->Min.y, gr->Max.y,'x'); - zz.Fill(gr->Min.z, gr->Max.z,'y'); - for(i=0;iGetNx()-1;i++) - { - register float v0 = v->v(i); - mgl_contf_gen(gr,v0,v->v(i+1),a,&xx,&yy,&zz,gr->GetC(ss,v0),0); - } - gr->EndGroup(); -} -//----------------------------------------------------------------------------- -void mgl_contf_y_val(HMGL gr, HCDT v, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContFY"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContFY"); return; } - gr->SaveState(opt); - static int cgid=1; gr->StartGroup("ContFY",cgid++); - mglData xx,yy,zz,aa; - long ss=gr->AddTexture(sch); - - if(l>1) - { - aa.Create(n,l); xx.Create(n,l); yy.Create(n,l); zz.Create(n,l); - float d = (m-1)*(sv - gr->Min.y)/(gr->Max.y - gr->Min.y); - k = long(d); d = d - k; - if(k>m-2) { k=m-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(i,k,j)*(1-d) + d*a->v(i,k+1,j); - a = &aa; - } - else - { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } - yy.Fill(sv, sv); - xx.Fill(gr->Min.x, gr->Max.x,'x'); - zz.Fill(gr->Min.z, gr->Max.z,'y'); - for(i=0;iGetNx()-1;i++) - { - register float v0 = v->v(i); - mgl_contf_gen(gr,v0,v->v(i+1),a,&xx,&yy,&zz,gr->GetC(ss,v0),0); - } - gr->EndGroup(); -} -//----------------------------------------------------------------------------- -void mgl_contf_z_val(HMGL gr, HCDT v, HCDT a, const char *sch, float sv, const char *opt) -{ - register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContFZ"); return; } - if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContFZ"); return; } - gr->SaveState(opt); - static int cgid=1; gr->StartGroup("ContFZ",cgid++); - mglData xx,yy,zz,aa; - long ss=gr->AddTexture(sch); - - xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); - if(l>1) - { - aa.Create(n,m); - float d = (l-1)*(sv - gr->Min.z)/(gr->Max.z - gr->Min.z); - k = long(d); d = d - k; - if(k>l-2) { k=l-2; d=1; } - if(k<0) { k=0; d=0; } - for(j=0;jv(i,j,k)*(1-d) + d*a->v(i,j,k+1); - a = &aa; - } - zz.Fill(sv, sv); - yy.Fill(gr->Min.y, gr->Max.y,'y'); - xx.Fill(gr->Min.x, gr->Max.x,'x'); - for(i=0;iGetNx()-1;i++) - { - register float v0 = v->v(i); - mgl_contf_gen(gr,v0,v->v(i+1),a,&xx,&yy,&zz,gr->GetC(ss,v0),0); - } - gr->EndGroup(); -} -//----------------------------------------------------------------------------- -void mgl_contf_x(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - float r = gr->SaveState(opt); - long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); - mglData v(Num); v.Fill(gr->Min.c, gr->Max.c); - mgl_contf_x_val(gr,&v,a,sch,sv,0); -} -//----------------------------------------------------------------------------- -void mgl_contf_y(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - float r = gr->SaveState(opt); - long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); - mglData v(Num); v.Fill(gr->Min.c, gr->Max.c); - mgl_contf_y_val(gr,&v,a,sch,sv,0); -} -//----------------------------------------------------------------------------- -void mgl_contf_z(HMGL gr, HCDT a, const char *sch, float sv, const char *opt) -{ - float r = gr->SaveState(opt); - long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); - mglData v(Num); v.Fill(gr->Min.c, gr->Max.c); - mgl_contf_z_val(gr,&v,a,sch,sv,0); -} -//----------------------------------------------------------------------------- -void mgl_contf_x_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_cont_z_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s; } +//----------------------------------------------------------------------------- +// +// ContFX, ContFY, ContFZ series +// +//----------------------------------------------------------------------------- +void mgl_contf_gen(HMGL gr, mreal v1, mreal v2, HCDT a, HCDT x, HCDT y, HCDT z, mreal c, long ak); +void mgl_contf_x_val(HMGL gr, HCDT v, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContFX"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContFX"); return; } + gr->SaveState(opt); + static int cgid=1; gr->StartGroup("ContFX",cgid++); + mglData xx,yy,zz,aa; + long ss=gr->AddTexture(sch); + + if(l>1) + { + aa.Create(m,l); xx.Create(m,l); yy.Create(m,l); zz.Create(m,l); + mreal d = (n-1)*(sv - gr->Min.x)/(gr->Max.x - gr->Min.x); + k = long(d); d = d - k; + if(k>n-2) { k=n-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+1+n*(i+m*j)]; + else for(j=0;jv(k,i,j)*(1-d) + d*a->v(k+1,i,j); + a = &aa; + } + else + { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } + xx.Fill(sv, sv); + yy.Fill(gr->Min.y, gr->Max.y,'x'); + zz.Fill(gr->Min.z, gr->Max.z,'y'); + for(i=0;iGetNx()-1;i++) + { + register mreal v0 = v->v(i); + mgl_contf_gen(gr,v0,v->v(i+1),a,&xx,&yy,&zz,gr->GetC(ss,v0),0); + } + gr->EndGroup(); +} +//----------------------------------------------------------------------------- +void mgl_contf_y_val(HMGL gr, HCDT v, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContFY"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContFY"); return; } + gr->SaveState(opt); + static int cgid=1; gr->StartGroup("ContFY",cgid++); + mglData xx,yy,zz,aa; + long ss=gr->AddTexture(sch); + + if(l>1) + { + aa.Create(n,l); xx.Create(n,l); yy.Create(n,l); zz.Create(n,l); + mreal d = (m-1)*(sv - gr->Min.y)/(gr->Max.y - gr->Min.y); + k = long(d); d = d - k; + if(k>m-2) { k=m-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+n+n*(i+m*j)]; + else for(j=0;jv(i,k,j)*(1-d) + d*a->v(i,k+1,j); + a = &aa; + } + else + { xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); } + yy.Fill(sv, sv); + xx.Fill(gr->Min.x, gr->Max.x,'x'); + zz.Fill(gr->Min.z, gr->Max.z,'y'); + for(i=0;iGetNx()-1;i++) + { + register mreal v0 = v->v(i); + mgl_contf_gen(gr,v0,v->v(i+1),a,&xx,&yy,&zz,gr->GetC(ss,v0),0); + } + gr->EndGroup(); +} +//----------------------------------------------------------------------------- +void mgl_contf_z_val(HMGL gr, HCDT v, HCDT a, const char *sch, mreal sv, const char *opt) +{ + register long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); + if(mgl_isnan(sv)) sv = gr->GetOrgX('x'); + if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"ContFZ"); return; } + if(svMin.x || sv>gr->Max.x) { gr->SetWarn(mglWarnSlc,"ContFZ"); return; } + gr->SaveState(opt); + static int cgid=1; gr->StartGroup("ContFZ",cgid++); + mglData xx,yy,zz,aa; + long ss=gr->AddTexture(sch); + + xx.Create(n,m); yy.Create(n,m); zz.Create(n,m); + if(l>1) + { + aa.Create(n,m); + mreal d = (l-1)*(sv - gr->Min.z)/(gr->Max.z - gr->Min.z); + k = long(d); d = d - k; + if(k>l-2) { k=l-2; d=1; } + if(k<0) { k=0; d=0; } + const mglData *ma=dynamic_cast(a); + if(ma) for(j=0;ja[k+n*(i+m*j)]*(1-d) + d*ma->a[k+n*m+n*(i+m*j)]; + else for(j=0;jv(i,j,k)*(1-d) + d*a->v(i,j,k+1); + a = &aa; + } + zz.Fill(sv, sv); + yy.Fill(gr->Min.y, gr->Max.y,'y'); + xx.Fill(gr->Min.x, gr->Max.x,'x'); + for(i=0;iGetNx()-1;i++) + { + register mreal v0 = v->v(i); + mgl_contf_gen(gr,v0,v->v(i+1),a,&xx,&yy,&zz,gr->GetC(ss,v0),0); + } + gr->EndGroup(); +} +//----------------------------------------------------------------------------- +void mgl_contf_x(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + mreal r = gr->SaveState(opt); + long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); + mglData v(Num); v.Fill(gr->Min.c, gr->Max.c); + mgl_contf_x_val(gr,&v,a,sch,sv,0); + gr->LoadState(); +} +//----------------------------------------------------------------------------- +void mgl_contf_y(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + mreal r = gr->SaveState(opt); + long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); + mglData v(Num); v.Fill(gr->Min.c, gr->Max.c); + mgl_contf_y_val(gr,&v,a,sch,sv,0); + gr->LoadState(); +} +//----------------------------------------------------------------------------- +void mgl_contf_z(HMGL gr, HCDT a, const char *sch, mreal sv, const char *opt) +{ + mreal r = gr->SaveState(opt); + long Num = (mgl_isnan(r) || r<=0) ? 7:long(r+0.5); + mglData v(Num); v.Fill(gr->Min.c, gr->Max.c); + mgl_contf_z_val(gr,&v,a,sch,sv,0); + gr->LoadState(); +} +//----------------------------------------------------------------------------- +void mgl_contf_x_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_contf_x(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -/// Draw several contour plots for data a at y = *sv -void mgl_contf_y_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_contf_x(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +/// Draw several contour plots for data a at y = *sv +void mgl_contf_y_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_contf_y(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -/// Draw several contour plots for data a at z = *sv -void mgl_contf_z_(uintptr_t *gr, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_contf_y(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +/// Draw several contour plots for data a at z = *sv +void mgl_contf_z_(uintptr_t *gr, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_contf_z(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } -/// Draw contour plots for data a at x = *sv -void mgl_contf_x_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_contf_z(_GR_, _DA_(a), s, *sv, o); delete []o; delete []s; } +/// Draw contour plots for data a at x = *sv +void mgl_contf_x_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_contf_x_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s;} -/// Draw contour plots for data a at y = *sv -void mgl_contf_y_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_contf_x_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s;} +/// Draw contour plots for data a at y = *sv +void mgl_contf_y_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_contf_y_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s;} -/// Draw contour plots for data a at z = *sv -void mgl_contf_z_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, float *sv, const char *opt,int l,int lo) -{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; + mgl_contf_y_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s;} +/// Draw contour plots for data a at z = *sv +void mgl_contf_z_val_(uintptr_t *gr, uintptr_t *v, uintptr_t *a, const char *sch, mreal *sv, const char *opt,int l,int lo) +{ char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; - mgl_contf_z_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s;} -//----------------------------------------------------------------------------- + mgl_contf_z_val(_GR_, _DA_(v), _DA_(a), s, *sv, o); delete []o; delete []s;} +//----------------------------------------------------------------------------- diff --git a/src/parser.cpp b/src/parser.cpp index 7015d6c..3e8af72 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -17,10 +17,7 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include -#include -//----------------------------------------------------------------------------- #include "mgl2/parser.h" #include "mgl2/canvas_cf.h" //----------------------------------------------------------------------------- @@ -35,24 +32,25 @@ void (*mgl_ask_func)(const wchar_t *, wchar_t *)=0; void mgl_ask_gets(const wchar_t *quest, wchar_t *res) { printf("%ls\n",quest); if(!fgetws(res,1024,stdin)) *res=0; } //----------------------------------------------------------------------------- -mglFunc::mglFunc(long p, const wchar_t *f, mglFunc *prev) +mglFunc::mglFunc(const mglFunc &f) +{ pos=f.pos; narg=f.narg; wcsncpy(func,f.func,64); } +mglFunc::mglFunc(long p, const wchar_t *f) { - pos = p; next = prev; - register long i; - for(i=0;(isalnum(f[i]) || f[i]=='_') && i<31;i++) func[i]=f[i]; - func[i]=0; - narg = wcstol(f+i+1,0,0); + pos = p; + register size_t i; + for(i=0;(isalnum(f[i]) || f[i]=='_') && i<63;i++) func[i]=f[i]; + func[i]=0; narg = wcstol(f+i+1,0,0); if(narg<0 || narg>9) narg=0; } //----------------------------------------------------------------------------- long mglParser::IsFunc(const wchar_t *name, int *na) { - mglFunc *f=func; - while(f) + register size_t i; + for(i=0;ifunc.c_str(), name)) - { if(na) *na=f->narg; return f->pos; } - f = f->next; + const mglFunc &f = func[i]; + if(!wcscmp(f.func, name)) + { if(na) *na=f.narg; return f.pos; } } return 0; } @@ -61,13 +59,12 @@ void mglParser::ScanFunc(const wchar_t *line) { static long num=0; if(!line) - { if(func) delete func; - num=0; func=0; return; } + { func.clear(); num=0; return; } num++; if(wcsncmp(line,L"func",4) || line[4]>' ') return; register long i; for(i=4;line[i]<=' ' || line[i]=='\'';i++); - func = new mglFunc(num-1, line+i, func); + func.push_back(mglFunc(num-1, line+i)); } //----------------------------------------------------------------------------- wchar_t *mgl_str_copy(const char *s) @@ -175,7 +172,7 @@ mglNum::~mglNum() //----------------------------------------------------------------------------- mglParser::mglParser(bool setsize) { - DataList=0; NumList=0; func=0; fn_stack=0; + DataList=0; NumList=0; fn_stack=0; // wchar_t *par[40]; ///< Parameter for substituting instead of $1, ..., $9 out=0; *leg=0; InUse = 1; Skip=Stop=for_br=false; @@ -201,7 +198,7 @@ mglParser::~mglParser() } for(long i=0;i<40;i++) if(par[i]) delete [](par[i]); delete []op1; delete []op2; delete []fval; - if(Cmd!=mgls_base_cmd) delete []Cmd; + if(Cmd && Cmd!=mgls_base_cmd) delete []Cmd; if(fn_stack) free(fn_stack); } //----------------------------------------------------------------------------- @@ -323,8 +320,11 @@ int mglFindArg(const wchar_t *str) if(str[i]=='\'') l++; if(str[i]=='{') k++; if(str[i]=='}') k--; - if(l%2==0 && k==0 && (str[i]=='#' || str[i]==';')) return -i; - if(l%2==0 && k==0 && (str[i]<=' ')) return i; + if(l%2==0 && k==0) + { + if(str[i]=='#' || str[i]==';') return -i; + if(str[i]<=' ') return i; + } } return 0; } @@ -523,11 +523,12 @@ int mglParser::Parse(mglGraph *gr, const wchar_t *string, long pos) for(n=0;nDataList=DataList; prs->NumList=NumList; prs->Cmd=Cmd; + for(i=10;i<30;i++) prs->AddParam(i,par[i]); + prs->Execute(gr,fp); + for(i=10;i<30;i++) AddParam(i,prs->par[i]); + DataList=prs->DataList; prs->DataList=0; + NumList =prs->NumList; prs->NumList=0; + prs->Cmd=0; delete prs; fclose(fp); + } else n=1; } } @@ -911,7 +923,7 @@ void mglParser::Execute(mglGraph *gr, int n, const wchar_t **text) for(i=0;iSetWarn(-1, NULL); + gr->SetWarn(-1, ""); gr->SetObjId(i+1); r = Parse(gr,text[i],i+1); if(r<0) { i = -r-2; continue; } @@ -936,6 +948,7 @@ void mglParser::Execute(mglGraph *gr, const wchar_t *text) memcpy(wcs, text, s*sizeof(wchar_t)); str[0] = wcs; n=1; long next=0; + Stop = false; for(i=0;i0) but only if dependence on variable 'i' is linear (i.e. ham = hre+i*him). -HMDT mgl_pde_solve(HMGL gr, const char *ham, HCDT ini_re, HCDT ini_im, float dz, float k0, const char *opt) +HMDT mgl_pde_solve(HMGL gr, const char *ham, HCDT ini_re, HCDT ini_im, mreal dz, mreal k0, const char *opt) { gr->SaveState(opt); mglPoint Min=gr->Min, Max=gr->Max; @@ -176,7 +176,7 @@ HMDT mgl_pde_solve(HMGL gr, const char *ham, HCDT ini_re, HCDT ini_im, float dz, } //----------------------------------------------------------------------------- // Solve GO ray equation like dr/dt = d ham/dp, dp/dt = -d ham/dr where ham = ham(x,y,z,p,q,v,t) and px=p, py=q, pz=v. The starting point (at t=0) is r0, p0. Result is array of {x,y,z,p,q,v,t} -HMDT mgl_ray_trace(const char *ham, float x0, float y0, float z0, float px, float py, float pz, float dt, float tmax) +HMDT mgl_ray_trace(const char *ham, mreal x0, mreal y0, mreal z0, mreal px, mreal py, mreal pz, mreal dt, mreal tmax) { mglData *res=new mglData; if(tmax(ray_dat); // NOTE: Ray must be mglData! diff --git a/src/pixel.cpp b/src/pixel.cpp index a74e384..92f618b 100644 --- a/src/pixel.cpp +++ b/src/pixel.cpp @@ -17,15 +17,13 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include -#include #include #include "mgl2/canvas.h" //----------------------------------------------------------------------------- void mglCanvas::SetSize(int w,int h) { if(w<=0 || h<=0) { SetWarn(mglWarnSize,"SetSize"); return; } - Width = w; Height = h; Depth = long(sqrt(w*h)); + Width = w; Height = h; Depth = long(sqrt(double(w*h))); if(G) { delete []G; delete []C; delete []Z; delete []G4;delete []OI; } G = new unsigned char[w*h*3]; G4= new unsigned char[w*h*4]; @@ -60,11 +58,11 @@ void mglCanvas::PostScale(mglPoint &p) const { mglPoint q=p/(2*B.pf); p.x = B.x + q.x*B.b[0] + q.y*B.b[1] + q.z*B.b[2]; - p.y = B.y+ q.x*B.b[3] + q.y*B.b[4] + q.z*B.b[5]; - p.z = B.z+ q.x*B.b[6] + q.y*B.b[7] + q.z*B.b[8]; + p.y = B.y + q.x*B.b[3] + q.y*B.b[4] + q.z*B.b[5]; + p.z = B.z + q.x*B.b[6] + q.y*B.b[7] + q.z*B.b[8]; /* if(Persp) { - register float d = (1-Persp*Depth/2)/(1-Persp*p.z); + register mreal d = (1-Persp*Depth/2)/(1-Persp*p.z); p.x = Width/2 + d*(p.x-Width/2); p.y = Height/2 + d*(p.y-Height/2); }*/ @@ -76,16 +74,19 @@ bool mglCanvas::ScalePoint(mglPoint &p, mglPoint &n, bool use_nan) const if(TernAxis&4) return res; PostScale(p); - mglPoint y=n/(2*B.pf); - n.x = y.x*B.b[0] + y.y*B.b[1] + y.z*B.b[2]; + mglPoint y=n; +// n.x = (B.b[4]*B.b[8]-B.b[5]*B.b[7])*y.x-(B.b[3]*B.b[8]-B.b[5]*B.b[6])*y.y+(B.b[3]*B.b[7]-B.b[4]*B.b[6])*y.z; +// n.y = (B.b[2]*B.b[7]-B.b[1]*B.b[8])*y.x+(B.b[0]*B.b[8]-B.b[2]*B.b[6])*y.y-(B.b[0]*B.b[7]-B.b[1]*B.b[6])*y.z; +// n.y = (B.b[1]*B.b[5]-B.b[2]*B.b[4])*y.x-(B.b[0]*B.b[5]-B.b[2]*B.b[3])*y.y+(B.b[0]*B.b[4]-B.b[1]*B.b[3])*y.z; + n.x = y.x*B.b[0] + y.y*B.b[1] + y.z*B.b[2]; // simpler for rotation only n.y = y.x*B.b[3] + y.y*B.b[4] + y.z*B.b[5]; n.z = y.x*B.b[6] + y.y*B.b[7] + y.z*B.b[8]; n.Normalize(); /* if(Persp) { - register float d = (1-Persp*Depth/2)/(1-Persp*p.z); + register mreal d = (1-Persp*Depth/2)/(1-Persp*p.z); // NOTE: No d* since I use transformed p here. - register float dd = Persp*n.z/(1-Persp*p.z); + register mreal dd = Persp*n.z/(1-Persp*p.z); n.x = d*n.x + dd*(p.x-Width/2); n.y = d*n.y + dd*(p.y-Height/2); }*/ @@ -98,7 +99,7 @@ long mglCanvas::ProjScale(int nf, long id) mglPoint pp(p0.x,p0.y,p0.z), nn(p0.u,p0.v,p0.w); if(mgl_isnan(pp.x)) return -1; mglPoint q=pp/(2*B.pf), p, n=nn; - register float w=B1.b[0]/2, h=B1.b[4]/2, d=B1.b[8]/2, xx=B1.x-w/2, yy=B1.y-h/2; + mreal w=B1.b[0]/2, h=B1.b[4]/2, d=B1.b[8]/2, xx=B1.x-w/2, yy=B1.y-h/2; if(TernAxis&1) // usual ternary axis { if(nf==0) @@ -169,10 +170,10 @@ void mglCanvas::LightScale() // NOTE: Perspective, transformation formulas and lists are not support just now !!! Also it use LAST InPlot parameters!!! mglPoint mglCanvas::CalcXYZ(int xs, int ys) const { - float s3 = 2*B.pf, x, y, z; // TODO: Take into account z-value of z-buffer + mreal s3 = 2*B.pf, x, y, z; // TODO: Take into account z-value of z-buffer ys = Height - ys; - float xx = xs-B.x, yy = ys-B.y; - float d1=B.b[0]*B.b[4]-B.b[1]*B.b[3], d2=B.b[1]*B.b[5]-B.b[2]*B.b[4], d3=B.b[0]*B.b[5]-B.b[2]*B.b[3]; + mreal xx = xs-B.x, yy = ys-B.y; + mreal d1=B.b[0]*B.b[4]-B.b[1]*B.b[3], d2=B.b[1]*B.b[5]-B.b[2]*B.b[4], d3=B.b[0]*B.b[5]-B.b[2]*B.b[3]; if(fabs(d1) > fabs(d2) && fabs(d1) > fabs(d3)) // x-y plane { z = 0; @@ -264,13 +265,13 @@ void mglCanvas::pxl_primdr(unsigned long id, unsigned long n, const void *) register unsigned long i; if(id +#define MCW MPI_COMM_WORLD +#define TAG_DATA_Z 0 +#define TAG_DATA_C 1 +void mglCanvas::MPI_Send(int id) +{ + ::MPI_Send(Z,3*Width*Height,MPI_FLOAT,id,TAG_DATA_Z,MCW); + ::MPI_Send(C,12*Width*Height,MPI_CHAR,id,TAG_DATA_C,MCW); +} +void mglCanvas::MPI_Recv(int id) +{ + Finish(); + MPI_Status status; + long n = Width*Height; + float *zz = new float[3*n]; + unsigned char *cc = new unsigned char[12*n]; + ::MPI_Recv(Z,3*n,MPI_FLOAT,id,TAG_DATA_Z,MCW,&status); + ::MPI_Recv(C,12*n,MPI_CHAR,id,TAG_DATA_C,MCW,&status); + // TODO check status for errors + register long i,j,k; + for(k=0;k1; - if(g) continue; + if(u<0 || v<0 || u+v>1) continue; if(Quality&2) // slow but accurate { p = p1+d1*u+d2*v; @@ -792,11 +825,19 @@ void mglCanvas::fast_draw(long k1, long k2, mglDrawReg *dr) y1=y1>dr->y1?y1:dr->y1; y2=y2y2?y2:dr->y2-1; if(x1>x2 || y1>y2) return; - register long i; + register long i, c; if(hor) for(i=x1;i<=x2;i++) - pnt_plot(i, p1.y+d.y*(i-p1.x)/d.x, p1.z+d.z*(i-p1.x)/d.x+pw, r); + { + c = long(p1.y+d.y*(i-p1.x)/d.x); + if(c>=y1 && c<=y2) + pnt_plot(i, c, p1.z+d.z*(i-p1.x)/d.x+pw, r); + } else for(i=y1;i<=y2;i++) - pnt_plot(p1.x+d.x*(i-p1.y)/d.y, i, p1.z+d.z*(i-p1.y)/d.y+pw, r); + { + c = long(p1.x+d.x*(i-p1.y)/d.y); + if(c>=x1 && c<=x2) + pnt_plot(c, i, p1.z+d.z*(i-p1.y)/d.y+pw, r); + } } //----------------------------------------------------------------------------- void mglCanvas::pnt_draw(long k, mglDrawReg *dr) @@ -820,13 +861,13 @@ void mglCanvas::pnt_draw(long k, mglDrawReg *dr) } } //----------------------------------------------------------------------------- -void mglCanvas::mark_draw(long k, char type, float size, mglDrawReg *d) +void mglCanvas::mark_draw(long k, char type, mreal size, mglDrawReg *d) { const mglPnt &q=Pnt[k]; unsigned char cs[4]; col2int(q,cs); cs[3] = size>0 ? 255 : 255*q.t; unsigned long pos = Pnt.size(), qos=pos; mglPnt p=q; - float ss=fabs(size)*0.35*font_factor; + mreal ss=fabs(size)*0.35*font_factor; register long i,j; #if MGL_HAVE_PTHREAD pthread_mutex_lock(&mutexPnt); @@ -834,7 +875,7 @@ void mglCanvas::mark_draw(long k, char type, float size, mglDrawReg *d) if(type=='.' || ss==0) pnt_draw(k,d); else { - float pw = PenWidth; PenWidth = 1; + mreal pw = PenWidth; PenWidth = 1; int pd = PDef; PDef = 0xffff; if(!strchr("xsSoO",type)) ss *= 1.1; switch(type) @@ -975,7 +1016,7 @@ void mglCanvas::mark_draw(long k, char type, float size, mglDrawReg *d) void mglCanvas::glyph_draw(const mglPrim *P, mglDrawReg *d) { mglPnt p=Pnt[P->n1]; - float f = p.w; + mreal f = p.w; #if MGL_HAVE_PTHREAD pthread_mutex_lock(&mutexPnt); #endif @@ -1001,12 +1042,12 @@ void mglCanvas::glyph_draw(const mglPrim *P, mglDrawReg *d) #endif } //----------------------------------------------------------------------------- -void mglCanvas::glyph_fill(const mglPnt &pp, float f, int nt, const short *trig, mglDrawReg *d) +void mglCanvas::glyph_fill(const mglPnt &pp, mreal f, int nt, const short *trig, mglDrawReg *d) { if(!trig || nt<=0) return; long ik,ii,pos=Pnt.size(); mglPnt p=pp; p.u=p.v=NAN; - float pw = Width>2 ? fabs(PenWidth) : 1e-5*Width; + mreal pw = Width>2 ? fabs(PenWidth) : 1e-5*Width; mglPoint p1,p2,p3; for(ik=0;ik2 ? fabs(PenWidth) : 1e-5*Width; + mreal pw = Width>2 ? fabs(PenWidth) : 1e-5*Width; unsigned pdef=PDef; PDef = 0xffff; - float opw=PenWidth; PenWidth=1; + mreal opw=PenWidth; PenWidth=1; mglPoint p1,p2,p3,p4; long pos=Pnt.size(); - float dy = 0.004; + mreal dy = 0.004; p1 = mglPoint(pp.u,pp.v-dy,0); PostScale(p1); p2 = mglPoint(pp.u,pp.v+dy,0); PostScale(p2); p3 = mglPoint(fabs(f)+pp.u,pp.v+dy,0); PostScale(p3); diff --git a/src/plot.cpp b/src/plot.cpp index b9bfd24..4dcc56b 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -20,7 +20,6 @@ #include "mgl2/plot.h" #include "mgl2/eval.h" #include "mgl2/data.h" -#include //----------------------------------------------------------------------------- // // Plot by formulas series @@ -29,14 +28,14 @@ void mgl_fplot(HMGL gr, const char *eqY, const char *pen, const char *opt) { if(eqY==0 || eqY[0]==0) return; // nothing to plot - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long n = (mgl_isnan(r) || r<=0) ? 100:long(r+0.5); - float *x = (float *)malloc(n*sizeof(float)); - float *y = (float *)malloc(n*sizeof(float)); + mreal *x = (mreal *)malloc(n*sizeof(mreal)); + mreal *y = (mreal *)malloc(n*sizeof(mreal)); mglFormula *eq = new mglFormula(eqY); register int i; - float d = (gr->Max.x - gr->Min.x)/(n-1.), xs, ys, yr, ym=fabs(gr->Max.y - gr->Min.y)/1000; + mreal d = (gr->Max.x - gr->Min.x)/(n-1.), xs, ys, yr, ym=fabs(gr->Max.y - gr->Min.y)/1000; #define islog(a, b) (((a)>0 && (b)>10*(a)) || ((b)<0 && (a)<10*(b))) // initial data filling if(gr->Min.x>0 && gr->Max.x>100*gr->Min.x) for(i=0,d=log(2*gr->Max.x/gr->Min.x)/(n-1);iCalc(xs); if(fabs(yr-ys)>ym) // bad approximation here { - x = (float *)realloc(x,(n+1)*sizeof(float)); - y = (float *)realloc(y,(n+1)*sizeof(float)); - memmove(x+i+2,x+i+1,(n-i-1)*sizeof(float)); - memmove(y+i+2,y+i+1,(n-i-1)*sizeof(float)); + x = (mreal *)realloc(x,(n+1)*sizeof(mreal)); + y = (mreal *)realloc(y,(n+1)*sizeof(mreal)); + memmove(x+i+2,x+i+1,(n-i-1)*sizeof(mreal)); + memmove(y+i+2,y+i+1,(n-i-1)*sizeof(mreal)); x[i+1] = xs; y[i+1] = yr; n++; } else i++; @@ -71,19 +70,19 @@ void mgl_fplot(HMGL gr, const char *eqY, const char *pen, const char *opt) //----------------------------------------------------------------------------- void mgl_fplot_xyz(HMGL gr, const char *eqX, const char *eqY, const char *eqZ, const char *pen, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long n = (mgl_isnan(r) || r<=0) ? 100:long(r+0.5); - float *x = (float *)malloc(n*sizeof(float)); - float *y = (float *)malloc(n*sizeof(float)); - float *z = (float *)malloc(n*sizeof(float)); - float *t = (float *)malloc(n*sizeof(float)); + mreal *x = (mreal *)malloc(n*sizeof(mreal)); + mreal *y = (mreal *)malloc(n*sizeof(mreal)); + mreal *z = (mreal *)malloc(n*sizeof(mreal)); + mreal *t = (mreal *)malloc(n*sizeof(mreal)); mglFormula *ex, *ey, *ez; ex = new mglFormula(eqX ? eqX : "0"); ey = new mglFormula(eqY ? eqY : "0"); ez = new mglFormula(eqZ ? eqZ : "0"); register int i; - float ts, xs, ys, zs, xr, yr, zr, xm=fabs(gr->Max.x - gr->Min.x)/1000, ym=fabs(gr->Max.y - gr->Min.y)/1000, zm=fabs(gr->Max.z - gr->Min.z)/1000; + mreal ts, xs, ys, zs, xr, yr, zr, xm=fabs(gr->Max.x - gr->Min.x)/1000, ym=fabs(gr->Max.y - gr->Min.y)/1000, zm=fabs(gr->Max.z - gr->Min.z)/1000; for(i=0;iStop) { delete ex; delete ey; delete ez; return; } @@ -102,14 +101,14 @@ void mgl_fplot_xyz(HMGL gr, const char *eqX, const char *eqY, const char *eqZ, c zs=(z[i]+z[i+1])/2; zr=ez->Calc(0,0,ts); if(fabs(xr-xs)>xm || fabs(yr-ys)>ym || fabs(zr-zs)>zm) // bad approximation here { - z = (float *)realloc(z,(n+1)*sizeof(float)); - t = (float *)realloc(t,(n+1)*sizeof(float)); - x = (float *)realloc(x,(n+1)*sizeof(float)); - y = (float *)realloc(y,(n+1)*sizeof(float)); - memmove(x+i+2,x+i+1,(n-i-1)*sizeof(float)); - memmove(y+i+2,y+i+1,(n-i-1)*sizeof(float)); - memmove(z+i+2,z+i+1,(n-i-1)*sizeof(float)); - memmove(t+i+2,t+i+1,(n-i-1)*sizeof(float)); + z = (mreal *)realloc(z,(n+1)*sizeof(mreal)); + t = (mreal *)realloc(t,(n+1)*sizeof(mreal)); + x = (mreal *)realloc(x,(n+1)*sizeof(mreal)); + y = (mreal *)realloc(y,(n+1)*sizeof(mreal)); + memmove(x+i+2,x+i+1,(n-i-1)*sizeof(mreal)); + memmove(y+i+2,y+i+1,(n-i-1)*sizeof(mreal)); + memmove(z+i+2,z+i+1,(n-i-1)*sizeof(mreal)); + memmove(t+i+2,t+i+1,(n-i-1)*sizeof(mreal)); t[i+1]=ts; x[i+1]=xr; y[i+1]=yr; z[i+1]=zr; n++; } else i++; @@ -147,15 +146,16 @@ void mgl_radar(HMGL gr, HCDT a, const char *pen, const char *opt) long n = a->GetNx(), ny=a->GetNy(); if(n<2) { gr->SetWarn(mglWarnLow,"Radar"); return; } mglData x(n+1,ny), y(n+1,ny); - float m=a->Minimal(), r=gr->SaveState(opt); + mreal m=a->Minimal(), r=gr->SaveState(opt); if(mgl_isnan(r) || r<0) r = m<0 ? -m:0; register long i,j; for(j=0;jv(i,j))*cos(2*i*M_PI/n); - y.a[i+(n+1)*j] = (r+a->v(i,j))*sin(2*i*M_PI/n); + register mreal v = a->v(i,j); + x.a[i+(n+1)*j] = (r+v)*cos(2*i*M_PI/n); + y.a[i+(n+1)*j] = (r+v)*sin(2*i*M_PI/n); } x.a[n+(n+1)*j] = r+a->v(0,j); y.a[n+(n+1)*j] = 0; } @@ -204,7 +204,8 @@ void mgl_candle_xyv(HMGL gr, HCDT x, HCDT v1, HCDT v2, HCDT y1, HCDT y2, const c bool sh = pen && strchr(pen,'!'); long n1,n2,n3,n4; - float m1,m2,xx,x1,x2,d; + mreal m1,m2,xx,x1,x2,d; + mreal zm = gr->AdjustZMin(); for(i=0;iStop) { if(d1) delete y1; if(d2) delete y2; return; } @@ -212,17 +213,17 @@ void mgl_candle_xyv(HMGL gr, HCDT x, HCDT v1, HCDT v2, HCDT y1, HCDT y2, const c d = iv(i+1)-xx : xx-x->v(i-1); x1 = xx + d/2*(1-gr->BarWidth); x2 = x1 + gr->BarWidth*d; xx = (x1+x2)/2; - n1 = gr->AddPnt(mglPoint(xx,y1->v(i),gr->Min.z)); - n2 = gr->AddPnt(mglPoint(xx,m1,gr->Min.z)); + n1 = gr->AddPnt(mglPoint(xx,y1->v(i),zm)); + n2 = gr->AddPnt(mglPoint(xx,m1,zm)); gr->line_plot(n1,n2); - n3 = gr->AddPnt(mglPoint(xx,y2->v(i),gr->Min.z)); - n4 = gr->AddPnt(mglPoint(xx,m2,gr->Min.z)); + n3 = gr->AddPnt(mglPoint(xx,y2->v(i),zm)); + n4 = gr->AddPnt(mglPoint(xx,m2,zm)); gr->line_plot(n3,n4); - n1 = gr->AddPnt(mglPoint(x1,m1,gr->Min.z)); - n2 = gr->AddPnt(mglPoint(x2,m1,gr->Min.z)); - n3 = gr->AddPnt(mglPoint(x1,m2,gr->Min.z)); - n4 = gr->AddPnt(mglPoint(x2,m2,gr->Min.z)); + n1 = gr->AddPnt(mglPoint(x1,m1,zm)); + n2 = gr->AddPnt(mglPoint(x2,m1,zm)); + n3 = gr->AddPnt(mglPoint(x1,m2,zm)); + n4 = gr->AddPnt(mglPoint(x2,m2,zm)); gr->line_plot(n1,n2); gr->line_plot(n1,n3); gr->line_plot(n4,n2); gr->line_plot(n4,n3); if(m1>m2) gr->quad_plot(n1,n2,n3,n4); @@ -233,11 +234,11 @@ void mgl_candle_xyv(HMGL gr, HCDT x, HCDT v1, HCDT v2, HCDT y1, HCDT y2, const c //----------------------------------------------------------------------------- void mgl_candle_yv(HMGL gr, HCDT v1, HCDT v2, HCDT y1, HCDT y2, const char *pen, const char *opt) { - if(v1->GetNx()<2) { gr->SetWarn(mglWarnLow,"Candle"); return; } gr->SaveState(opt); mglData x(v1->GetNx()+1); x.Fill(gr->Min.x,gr->Max.x); mgl_candle_xyv(gr,&x,v1,v2,y1,y2,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_candle(HMGL gr, HCDT v1, HCDT y1, HCDT y2, const char *pen, const char *opt) @@ -270,14 +271,14 @@ void mgl_candle_(uintptr_t *gr, uintptr_t *y, uintptr_t *y1, uintptr_t *y2, cons void mgl_plot_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char *opt) { long j,m,mx,my,mz,n=y->GetNx(),pal; - if(x->GetNx()!=n || z->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Plot"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Plot"); return; } + if(mgl_check_dim1(gr,x,y,z,0,"Plot")) return; + static int cgid=1; gr->StartGroup("Plot",cgid++); gr->SaveState(opt); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; char mk=gr->SetPenPal(pen,&pal); gr->Reserve(2*n*m); bool t1,t2,t3; - mglPoint p1,p2,p3,nn; + mglPoint p1,nn,p2,pt; long n1=-1,n2=-1,n3=-1; bool sh = pen && strchr(pen,'!'); @@ -290,7 +291,7 @@ void mgl_plot_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * for(i=0;iStop) return; - if(i>0) { n2=n1; p2=p1; t2=t1; } + if(i>0) { n2=n1; p2 = p1; t2=t1; } p1 = mglPoint(x->v(i,mx), y->v(i,my), z->v(i,mz)); n1 = gr->AddPnt(p1); t1 = n1>=0; if(mk && t1) gr->mark_plot(n1,mk); @@ -303,14 +304,14 @@ void mgl_plot_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * if(i>0 && ((t1 && !t2) || (t2 && !t1))) // do smoothing { - float i1=0, i2=1, ii; - p3=p1; t3=t1; n3=n1; // copy current + mreal i1=0, i2=1, ii; + t3=t1; n3=n1; // copy current do { ii = (i1+i2)/2; - p1.x = x->v(i,mx)*ii+x->v(i-1,mx)*(1-ii); - p1.y = y->v(i,my)*ii+y->v(i-1,my)*(1-ii); - p1.z = z->v(i,mz)*ii+z->v(i-1,mz)*(1-ii); - n1 = gr->AddPnt(p1); t1 = n1>=0; + pt.x = p1.x*ii+p2.x*(1-ii); + pt.y = p1.y*ii+p2.y*(1-ii); + pt.z = p1.z*ii+p2.z*(1-ii); + n1 = gr->AddPnt(pt); t1 = n1>=0; if((t1 && t3) || (t2 && !t1)) i2 = ii; else i1 = ii; } while(fabs(i2-i1)>1e-3); @@ -327,18 +328,21 @@ void mgl_plot_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) { gr->SaveState(opt); mglData z(y->GetNx()); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_plot_xyz(gr,x,y,&z,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_plot(HMGL gr, HCDT y, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Plot"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"Plot"); return; } gr->SaveState(opt); - mglData x(y->GetNx()), z(y->GetNx()); + mglData x(n), z(n); x.Fill(gr->Min.x,gr->Max.x); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_plot_xyz(gr,&x,y,&z,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_plot_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *pen, const char *opt,int l,int lo) @@ -363,16 +367,15 @@ void mgl_plot_(uintptr_t *gr, uintptr_t *y, const char *pen, const char *opt,int void mgl_tens_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT c, const char *pen, const char *opt) { long j,m,mx,my,mz,mc,n=y->GetNx(), pal; - if(x->GetNx()!=n || z->GetNx()!=n || c->GetNx()!=n) - { gr->SetWarn(mglWarnDim,"Tens"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Tens"); return; } + if(mgl_check_dim1(gr,x,y,z,0,"Tens")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Tens",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; char mk=gr->SetPenPal(pen, &pal); gr->Reserve(2*n*m); long ss=gr->AddTexture(pen); bool t1,t2,t3; - mglPoint p1,p2,p3,nn; + mglPoint p1,p2,pt,nn; long n1=-1,n2=-1,n3=-1; for(j=0;j0 && ((t1 && !t2) || (t2 && !t1))) // do smoothing { - float i1=0, i2=1, ii; - p3=p1; t3=t1; n3=n1; // copy current + mreal i1=0, i2=1, ii; + t3=t1; n3=n1; // copy current do { ii = (i1+i2)/2; - p1.x = x->v(i,mx)*ii+x->v(i-1,mx)*(1-ii); - p1.y = y->v(i,my)*ii+y->v(i-1,my)*(1-ii); - p1.z = z->v(i,mz)*ii+z->v(i-1,mz)*(1-ii); - p1.c = c->v(i,mc)*ii+c->v(i-1,mc)*(1-ii); - n1 = gr->AddPnt(p1,gr->GetC(ss,p1.c)); t1 = n1>=0; + pt.x = p1.x*ii+p2.x*(1-ii); + pt.y = p1.y*ii+p2.y*(1-ii); + pt.z = p1.z*ii+p2.z*(1-ii); + pt.c = p1.c*ii+p2.c*(1-ii); + n1 = gr->AddPnt(pt,gr->GetC(ss,pt.c)); t1 = n1>=0; if((t1 && t3) || (t2 && !t1)) i2 = ii; else i1 = ii; } while(fabs(i2-i1)>1e-3); @@ -421,18 +424,21 @@ void mgl_tens_xy(HMGL gr, HCDT x, HCDT y, HCDT c, const char *pen, const char *o { gr->SaveState(opt); mglData z(y->GetNx()); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_tens_xyz(gr,x,y,&z,c,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tens(HMGL gr, HCDT y, HCDT c, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Tens"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"Tens"); return; } gr->SaveState(opt); - mglData x(y->GetNx()), z(y->GetNx()); + mglData x(n), z(n); x.Fill(gr->Min.x,gr->Max.x); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_tens_xyz(gr,&x,y,&z,c,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tens_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *c, const char *pen, const char *opt,int l,int lo) @@ -457,16 +463,16 @@ void mgl_tens_(uintptr_t *gr, uintptr_t *y, uintptr_t *c, const char *pen, const void mgl_area_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char *opt) { long i,j,n=y->GetNx(),m,mx,my,mz,pal; - if(n<2) { gr->SetWarn(mglWarnLow,"Area"); return; } - if(x->GetNx()!=n || z->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Area"); return; } + if(mgl_check_dim1(gr,x,y,z,0,"Area")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Area3",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; bool sh = pen && strchr(pen,'!'); bool wire = pen && strchr(pen,'#'); - float z0=gr->GetOrgZ('x'); - float c1,c2; + mreal z0=gr->GetOrgZ('x'); + mreal c1,c2; mglPoint p1,p2,p3,p4,nn; long n1,n2,n3,n4; gr->SetPenPal(pen,&pal); gr->Reserve(2*n*m); @@ -478,15 +484,15 @@ void mgl_area_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * mx = jGetNy() ? j:0; my = jGetNy() ? j:0; mz = jGetNy() ? j:0; nn = mglPoint(-y->dvx(0,my),x->dvx(0,mx)); - n1 = gr->AddPnt(mglPoint(x->v(0,mx),y->v(0,my),z->v(0,mz)),c1,nn); - n2 = gr->AddPnt(mglPoint(x->v(0,mx),y->v(0,my),z0),c2,nn); + mglPoint p = mglPoint(x->v(0,mx),y->v(0,my),z->v(0,mz)); + n1 = gr->AddPnt(p,c1,nn); p.z = z0; n2 = gr->AddPnt(p,c2,nn); for(i=1;iStop) return; n3=n1; n4=n2; nn = mglPoint(-y->dvx(i,my),x->dvx(i,mx)); - n1 = gr->AddPnt(mglPoint(x->v(i,mx),y->v(i,my),z->v(i,mz)),c1,nn); - n2 = gr->AddPnt(mglPoint(x->v(i,mx),y->v(i,my),z0),c2,nn); + p = mglPoint(x->v(i,mx),y->v(i,my),z->v(i,mz)); + n1 = gr->AddPnt(p,c1,nn); p.z = z0; n2 = gr->AddPnt(p,c2,nn); if(wire) { gr->line_plot(n1,n2); gr->line_plot(n3,n4); @@ -502,12 +508,13 @@ void mgl_area_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * void mgl_area_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) { long i,j,n=y->GetNx(),m=y->GetNy(),mx,my,pal; - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Area"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Area"); return; } + if(mgl_check_dim1(gr,x,y,0,0,"Area")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Curve",cgid++); - float y0=gr->GetOrgY('x'), z0; - float c1,c2; + mreal zm = gr->AdjustZMin(); + mreal y0=gr->GetOrgY('x'), z0; + mreal c1,c2; mglPoint nn=mglPoint(0,0,1); long n1,n2,n3,n4; bool sh = pen && strchr(pen,'!'); @@ -520,16 +527,16 @@ void mgl_area_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) c2=c1=gr->NextColor(pal); if(gr->GetNumPal(pal)==2*m && !sh) c2=gr->NextColor(pal); mx = jGetNy() ? j:0; my = jGetNy() ? j:0; - z0 = gr->Min.z + (m-1-j)*(gr->Max.z-gr->Min.z)/m; + z0 = zm + (m-1-j)*(gr->Max.z-zm)/m; - n1 = gr->AddPnt(mglPoint(x->v(0,mx),y->v(0,my),z0),c1,nn); - n2 = gr->AddPnt(mglPoint(x->v(0,mx),y0,z0),c2,nn); + mglPoint p = mglPoint(x->v(0,mx),y->v(0,my),z0); + n1 = gr->AddPnt(p,c1,nn); p.y = y0; n2 = gr->AddPnt(p,c2,nn); for(i=1;iStop) return; n3=n1; n4=n2; - n1 = gr->AddPnt(mglPoint(x->v(i,mx),y->v(i,my),z0),c1,nn); - n2 = gr->AddPnt(mglPoint(x->v(i,mx),y0,z0),c2,nn); + p = mglPoint(x->v(i,mx),y->v(i,my),z0); + n1 = gr->AddPnt(p,c1,nn); p.y = y0; n2 = gr->AddPnt(p,c2,nn); if(wire) { gr->line_plot(n1,n2); gr->line_plot(n3,n4); @@ -544,11 +551,11 @@ void mgl_area_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) //----------------------------------------------------------------------------- void mgl_area(HMGL gr, HCDT y, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Area"); return; } gr->SaveState(opt); mglData x(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); mgl_area_xy(gr,&x,y,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_area_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *pen, const char *opt,int l,int lo) @@ -573,15 +580,16 @@ void mgl_area_(uintptr_t *gr, uintptr_t *y, const char *pen, const char *opt,int void mgl_region_xy(HMGL gr, HCDT x, HCDT y1, HCDT y2, const char *pen, const char *opt) { long i,j, n=y1->GetNx(), m=y1->GetNy(), mx, pal; - if(x->GetNx()!=n || y2->GetNx()!=n || y2->GetNy()!=m) - { gr->SetWarn(mglWarnDim,"Region"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Region"); return; } + if(mgl_check_dim1(gr,x,y1,y2,0,"Region")) return; + if(y2->GetNy()!=m) { gr->SetWarn(mglWarnDim,"Region"); return; } + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Region",cgid++); - float c1,c2; + mreal c1,c2; mglPoint nn=mglPoint(0,0,1); long n1,n2,n3,n4; - float xx,f1,f2,f3,f4; + mreal xx,f1,f2,f3,f4; + mreal zm = gr->AdjustZMin(); bool inside = (pen && strchr(pen,'i')); // NOTE: check if 'i' is free (used here for inside flag) bool sh = pen && strchr(pen,'!'); @@ -592,7 +600,7 @@ void mgl_region_xy(HMGL gr, HCDT x, HCDT y1, HCDT y2, const char *pen, const cha c2=c1=gr->NextColor(pal); if(gr->GetNumPal(pal)==2*m && !sh) c2=gr->NextColor(pal); mx = jGetNy() ? j:0; - float z0 = gr->Min.z + (m-1-j)*(gr->Max.z-gr->Min.z)/m; + mreal z0 = zm + (m-1-j)*(gr->Max.z-zm)/m; f1 = y1->v(0,j); f2 = y2->v(0,j); xx = x->v(0,mx); n1 = gr->AddPnt(mglPoint(xx,f1,z0),c1,nn); @@ -615,8 +623,9 @@ void mgl_region(HMGL gr, HCDT y1, HCDT y2, const char *pen, const char *opt) { gr->SaveState(opt); mglData x(y1->GetNx()); - x.Fill(gr->Min.z, gr->Max.z); + x.Fill(gr->Min.x, gr->Max.x); mgl_region_xy(gr,&x,y1,y2,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_region_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y1, uintptr_t *y2, const char *pen, const char *opt, int l, int lo) @@ -636,8 +645,8 @@ void mgl_region_(uintptr_t *gr, uintptr_t *y1, uintptr_t *y2, const char *pen, c void mgl_step_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char *opt) { long i,j,m,mx,my,mz,n=y->GetNx(), pal; - if(x->GetNx()!=n || z->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Step"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Step"); return; } + if(mgl_check_dim1(gr,x,y,z,0,"Step")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Step3",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; @@ -645,6 +654,7 @@ void mgl_step_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * char mk=gr->SetPenPal(pen,&pal); gr->Reserve(2*n*m); long n1,n2; + mglPoint p; for(j=0;jGetNy() ? j:0; my = jGetNy() ? j:0; @@ -655,12 +665,12 @@ void mgl_step_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * { if(gr->Stop) return; n2 = n1; // horizontal - n1 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my), z->v(i-1,mz))); - gr->line_plot(n1,n2); + p = mglPoint(x->v(i,mx), y->v(i,my), z->v(i-1,mz)); + n1 = gr->AddPnt(p); gr->line_plot(n1,n2); if(i==1) gr->arrow_plot(n1,n2,gr->Arrow1); n2 = n1; // vertical - n1 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my), z->v(i,mz))); + p.z = z->v(i,mz); n1 = gr->AddPnt(p); if(mk) gr->mark_plot(n1,mk); gr->line_plot(n1,n2); if(i==n-1) gr->arrow_plot(n1,n2,gr->Arrow2); @@ -673,16 +683,17 @@ void mgl_step_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * void mgl_step_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) { long i,j,m,mx,my,n=y->GetNx(), pal; - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Step"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Step"); return; } + if(mgl_check_dim1(gr,x,y,0,0,"Step")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Step",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); bool sh = pen && strchr(pen,'!'); - float zVal = gr->Min.z; + mreal zVal =gr->AdjustZMin(); char mk=gr->SetPenPal(pen,&pal); gr->Reserve(2*n*m); long n1,n2; + mglPoint p; for(j=0;jGetNy() ? j:0; my = jGetNy() ? j:0; @@ -693,12 +704,12 @@ void mgl_step_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) { if(gr->Stop) return; n2 = n1; // horizontal - n1 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i-1,my), zVal)); - gr->line_plot(n1,n2); + p = mglPoint(x->v(i,mx), y->v(i-1,my), zVal); + n1 = gr->AddPnt(p); gr->line_plot(n1,n2); if(i==1) gr->arrow_plot(n1,n2,gr->Arrow1); n2 = n1; // vertical - n1 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my), zVal)); + p.y = y->v(i,my); n1 = gr->AddPnt(p); if(mk) gr->mark_plot(n1,mk); gr->line_plot(n1,n2); if(i==n-1) gr->arrow_plot(n1,n2,gr->Arrow2); @@ -710,11 +721,11 @@ void mgl_step_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) //----------------------------------------------------------------------------- void mgl_step(HMGL gr, HCDT y, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Step"); return; } gr->SaveState(opt); mglData x(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); mgl_step_xy(gr,&x,y,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_step_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *pen, const char *opt,int l,int lo) @@ -739,14 +750,14 @@ void mgl_step_(uintptr_t *gr, uintptr_t *y, const char *pen, const char *opt,int void mgl_stem_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char *opt) { long i,j,m,mx,my,mz,n=y->GetNx(), pal; - if(x->GetNx()!=n || z->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Stem"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Stem"); return; } + if(mgl_check_dim1(gr,x,y,z,0,"Stem")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Stem3",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; bool sh = pen && strchr(pen,'!'); - float z0=gr->GetOrgZ('x'); + mreal z0=gr->GetOrgZ('x'); char mk=gr->SetPenPal(pen,&pal); gr->Reserve(2*n*m); long n1,n2; for(j=0;jGetNx(), pal; - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Stem"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Stem"); return; } + if(mgl_check_dim1(gr,x,y,0,0,"Stem")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Stem",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); bool sh = pen && strchr(pen,'!'); - float zVal = gr->Min.z; - float y0=gr->GetOrgY('x'); + mreal zVal = gr->AdjustZMin(), y0=gr->GetOrgY('x'), vv; char mk=gr->SetPenPal(pen,&pal); gr->Reserve(2*n*m); long n1,n2; for(j=0;jStop) return; - n1 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my), zVal)); + vv = x->v(i,mx); + n1 = gr->AddPnt(mglPoint(vv, y->v(i,my), zVal)); if(mk) gr->mark_plot(n1,mk); - n2 = gr->AddPnt(mglPoint(x->v(i,mx), y0, zVal)); + n2 = gr->AddPnt(mglPoint(vv, y0, zVal)); gr->line_plot(n1,n2); if(sh) gr->NextColor(pal); } @@ -799,11 +810,11 @@ void mgl_stem_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) //----------------------------------------------------------------------------- void mgl_stem(HMGL gr, HCDT y, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Stem"); return; } gr->SaveState(opt); mglData x(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); mgl_stem_xy(gr,&x,y,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_stem_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *pen, const char *opt,int l,int lo) @@ -828,8 +839,8 @@ void mgl_stem_(uintptr_t *gr, uintptr_t *y, const char *pen, const char *opt,int void mgl_bars_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char *opt) { long i,j,m,mx,my,mz,n=z->GetNx(), pal,nx=x->GetNx(),ny=y->GetNx(); - if(nxSetWarn(mglWarnDim,"Bars"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Bars"); return; } + if(mgl_check_dim1(gr,x,z,y,0,"Bars",true)) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Bars3",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; @@ -838,11 +849,11 @@ void mgl_bars_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * bool wire = pen && strchr(pen,'#'); bool above = pen && strchr(pen,'a'), fall = pen && strchr(pen,'f'); if(above) fall = false; - float c1,c2,c; + mreal c1,c2,c; mglPoint p1,p2,p3,p4,nn; long n1,n2,n3,n4; - float *dd=new float[n], x1,x2,y1,y2,z0,zz,zp,d; - memset(dd,0,n*sizeof(float)); + mreal *dd=new mreal[n], x1,x2,y1,y2,z0,zz,zp,d,vv; + memset(dd,0,n*sizeof(mreal)); gr->SetPenPal(pen,&pal); if(wire) gr->Reserve(4*n*m); else gr->Reserve(4*n*m); @@ -855,11 +866,11 @@ void mgl_bars_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * for(i=0;iStop) { delete []dd; return; } - d = iv(i+1,mx)-x->v(i,mx) : x->v(i,mx)-x->v(i-1,mx); - x1 = x->v(i,mx) + d/2*(1-gr->BarWidth); x2 = x1 + gr->BarWidth*d; - d = iv(i+1,my)-y->v(i,my) : y->v(i,my)-y->v(i-1,my); - y1 = y->v(i,my) + d/2*(1-gr->BarWidth); y2 = y1 + gr->BarWidth*d; - zz = z->v(i,mz); + vv = x->v(i,mx); d = iv(i+1,mx)-vv : vv-x->v(i-1,mx); + x1 = vv + d/2*(1-gr->BarWidth); x2 = x1 + gr->BarWidth*d; + vv = y->v(i,my); d = iv(i+1,my)-vv : vv-y->v(i-1,my); + y1 = vv + d/2*(1-gr->BarWidth); y2 = y1 + gr->BarWidth*d; + vv = zz = z->v(i,mz); if(!above) { x2 = (x2-x1)/m; x1 += j*x2; x2 += x1; @@ -869,7 +880,7 @@ void mgl_bars_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * { z0 = gr->GetOrgZ('x') + dd[i]; dd[i] += zz; zz += z0; } if(fall) { z0 = zp; zz += z0; zp = zz; } - c = z->v(i,mz)<0 ? c1 : c2; + c = vv<0 ? c1 : c2; nn = mglPoint(-y->dvx(i,my),x->dvx(i,mx)); p1 = mglPoint(x1,y1,zz); p2 = mglPoint(x1,y1,z0); p3 = mglPoint(x2,y2,z0); p4 = mglPoint(x2,y2,zz); @@ -895,20 +906,21 @@ void mgl_bars_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * void mgl_bars_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) { long i,j,m,mx,my,n=y->GetNx(),pal; - if(x->GetNx()SetWarn(mglWarnDim,"Bars"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Bars"); return; } + if(mgl_check_dim1(gr,x,y,0,0,"Bars",true)) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Bars",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); bool sh = pen && strchr(pen,'!'); bool wire = pen && strchr(pen,'#'); - bool above = pen && strchr(pen,'a')!=0, fall = pen && strchr(pen,'f')!=0; + bool above = pen && strchr(pen,'a'), fall = pen && strchr(pen,'f'); if(above) fall = false; - float c1,c2,c; + mreal c1,c2,c; long n1,n2,n3,n4; - float *dd=new float[n], x1,x2,yy,y0,yp,d; - memset(dd,0,n*sizeof(float)); + mreal *dd=new mreal[n], x1,x2,yy,y0,yp,d,vv; + mreal zm = gr->AdjustZMin(); + memset(dd,0,n*sizeof(mreal)); gr->SetPenPal(pen,&pal); if(wire) gr->Reserve(4*n*m); else gr->Reserve(4*n*m); @@ -917,24 +929,24 @@ void mgl_bars_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) c2=c1=gr->NextColor(pal); if(gr->GetNumPal(pal)==2*m && !sh) c2 = gr->NextColor(pal); mx = jGetNy() ? j:0; my = jGetNy() ? j:0; - yp = y0 = gr->GetOrgZ('x'); + yp = y0 = gr->GetOrgY('x'); for(i=0;iStop) { delete []dd; return; } - d = iv(i+1,mx)-x->v(i,mx) : x->v(i,mx)-x->v(i-1,mx); - x1 = x->v(i,mx) + d/2*(1-gr->BarWidth); - x2 = x1 + gr->BarWidth*d; yy = y->v(i,my); + vv = x->v(i,mx); d = iv(i+1,mx)-vv : vv-x->v(i-1,mx); + x1 = vv + d/2*(1-gr->BarWidth); x2 = x1 + gr->BarWidth*d; + vv = yy = y->v(i,my); if(!above) { x2 = (x2-x1)/m; x1 += j*x2; x2 += x1; } else { y0 = gr->GetOrgY('x') + dd[i]; dd[i] += yy; yy += y0; } if(fall) { y0 = yp; yy += y0; yp = yy; } - c = (y->v(i,my)<0) ? c1 : c2; - n1 = gr->AddPnt(mglPoint(x1,yy,gr->Min.z),c); - n2 = gr->AddPnt(mglPoint(x1,y0,gr->Min.z),c); - n3 = gr->AddPnt(mglPoint(x2,y0,gr->Min.z),c); - n4 = gr->AddPnt(mglPoint(x2,yy,gr->Min.z),c); + c = vv<0 ? c1 : c2; + n1 = gr->AddPnt(mglPoint(x1,yy,zm),c); + n2 = gr->AddPnt(mglPoint(x1,y0,zm),c); + n3 = gr->AddPnt(mglPoint(x2,y0,zm),c); + n4 = gr->AddPnt(mglPoint(x2,yy,zm),c); if(wire) { gr->line_plot(n1,n2); gr->line_plot(n1,n4); @@ -949,11 +961,11 @@ void mgl_bars_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) //----------------------------------------------------------------------------- void mgl_bars(HMGL gr, HCDT y, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Bars"); return; } gr->SaveState(opt); mglData x(y->GetNx()+1); x.Fill(gr->Min.x,gr->Max.x); mgl_bars_xy(gr,&x,y,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_bars_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *pen, const char *opt,int l,int lo) @@ -978,8 +990,8 @@ void mgl_bars_(uintptr_t *gr, uintptr_t *y, const char *pen, const char *opt,int void mgl_barh_yx(HMGL gr, HCDT y, HCDT v, const char *pen, const char *opt) { long i,j,m,mx,my,n=v->GetNx(),pal; - if(y->GetNx()SetWarn(mglWarnDim,"Barh"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Barh"); return; } + if(mgl_check_dim1(gr,y,v,0,0,"Barh",true)) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Barh",cgid++); m = y->GetNy() > v->GetNy() ? y->GetNy() : v->GetNy(); @@ -988,10 +1000,11 @@ void mgl_barh_yx(HMGL gr, HCDT y, HCDT v, const char *pen, const char *opt) bool wire = pen && strchr(pen,'#'); bool above = pen && strchr(pen,'a'), fall = pen && strchr(pen,'f'); if(above) fall = false; - float c1,c2,c; + mreal c1,c2,c; long n1,n2,n3,n4; - float *dd=new float[n], y1,y2,xx,x0,xp,d; - memset(dd,0,n*sizeof(float)); + mreal *dd=new mreal[n], y1,y2,xx,x0,xp,d,vv; + mreal zm = gr->AdjustZMin(); + memset(dd,0,n*sizeof(mreal)); gr->SetPenPal(pen,&pal); if(wire) gr->Reserve(4*n*m); else gr->Reserve(4*n*m); @@ -1004,20 +1017,20 @@ void mgl_barh_yx(HMGL gr, HCDT y, HCDT v, const char *pen, const char *opt) for(i=0;iStop) { delete []dd; return; } - d = iv(i+1,my)-y->v(i,my) : y->v(i,my)-y->v(i-1,my); - y1 = y->v(i,my) + d/2*(1-gr->BarWidth); - y2 = y1 + gr->BarWidth*d; xx = v->v(i,mx); + vv = y->v(i,my); d = iv(i+1,my)-vv : vv-y->v(i-1,my); + y1 = vv + d/2*(1-gr->BarWidth); y2 = y1 + gr->BarWidth*d; + vv = xx = v->v(i,mx); if(!above) { y2 = (y2-y1)/m; y1 += j*y2; y2 += y1; } else { x0 = gr->GetOrgX('y') + dd[i]; dd[i] += xx; xx += x0; } if(fall) { x0 = xp; xx += x0; xp = xx; } - c = (v->v(i,mx)<0) ? c1 : c2; - n1 = gr->AddPnt(mglPoint(xx,y1,gr->Min.z),c); - n2 = gr->AddPnt(mglPoint(xx,y2,gr->Min.z),c); - n3 = gr->AddPnt(mglPoint(x0,y2,gr->Min.z),c); - n4 = gr->AddPnt(mglPoint(x0,y1,gr->Min.z),c); + c = vv<0 ? c1 : c2; + n1 = gr->AddPnt(mglPoint(xx,y1,zm),c); + n2 = gr->AddPnt(mglPoint(xx,y2,zm),c); + n3 = gr->AddPnt(mglPoint(x0,y2,zm),c); + n4 = gr->AddPnt(mglPoint(x0,y1,zm),c); if(wire) { gr->line_plot(n1,n2); gr->line_plot(n1,n4); @@ -1032,11 +1045,11 @@ void mgl_barh_yx(HMGL gr, HCDT y, HCDT v, const char *pen, const char *opt) //----------------------------------------------------------------------------- void mgl_barh(HMGL gr, HCDT v, const char *pen, const char *opt) { - if(v->GetNx()<2) { gr->SetWarn(mglWarnLow,"Barh"); return; } gr->SaveState(opt); mglData y(v->GetNx()+1); y.Fill(gr->Min.y,gr->Max.y); mgl_barh_yx(gr,&y,v,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_barh_yx_(uintptr_t *gr, uintptr_t *y, uintptr_t *v, const char *pen, const char *opt,int l,int lo) @@ -1056,29 +1069,32 @@ void mgl_barh_(uintptr_t *gr, uintptr_t *v, const char *pen, const char *opt,int double sgn(double a); int mgl_cmp_flt(const void *a, const void *b) { - const float *aa = (const float *)a; - const float *bb = (const float *)b; + const mreal *aa = (const mreal *)a; + const mreal *bb = (const mreal *)b; return int(sgn(*aa-*bb)); } //----------------------------------------------------------------------------- void mgl_boxplot_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) { long n=y->GetNx(), m=y->GetNy(), nx=x->GetNx(); - if(nxSetWarn(mglWarnDim,"BoxPlot"); return; } + if(nxSetWarn(mglWarnDim,"BoxPlot"); return; } gr->SaveState(opt); static int cgid=1; gr->StartGroup("BoxPlot",cgid++); - float *b = new float[5*n], *d = new float[m], x1, x2, dd; - float zVal = gr->Min.z; + mreal *b = new mreal[5*n], *d = new mreal[m], x1, x2, dd; + mreal zVal = gr->AdjustZMin(), vv; bool sh = pen && strchr(pen,'!'); register long i,j; for(i=0;iStop) { delete []d; return; } register long mm,k; - for(mm=j=0;jv(i,j))) - { d[mm]=y->v(i,j); mm++; } + for(mm=j=0;jv(i,j); + if(!mgl_isnan(vv)) { d[mm]=vv; mm++; } + } if(m==0) { b[i]=NAN; break; } - qsort(d, mm, sizeof(float), mgl_cmp_flt); + qsort(d, mm, sizeof(mreal), mgl_cmp_flt); b[i] = d[0]; b[i+4*n] = d[mm-1]; k = mm/4; b[i+n] = (mm%4) ? d[k] : (d[k]+d[k-1])/2.; b[i+2*n] = (mm%2) ? d[mm/2] : (d[mm/2]+d[mm/2-1])/2.; @@ -1092,8 +1108,9 @@ void mgl_boxplot_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) for(i=0;iStop) { delete []b; return; } - dd = iv(i+1)-x->v(i) : x->v(i)-x->v(i-1); - x1 = x->v(i) + dd/2*(1-gr->BarWidth); + vv = x->v(i); + dd = iv(i+1)-vv : vv-x->v(i-1); + x1 = vv + dd/2*(1-gr->BarWidth); x2 = x1 + gr->BarWidth*dd; for(j=0;j<5;j++) // horizontal lines { @@ -1121,11 +1138,11 @@ void mgl_boxplot_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) //----------------------------------------------------------------------------- void mgl_boxplot(HMGL gr, HCDT y, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"BoxPlot"); return; } gr->SaveState(opt); mglData x(y->GetNx()+1); x.Fill(gr->Min.x,gr->Max.x); mgl_boxplot_xy(gr,&x,y,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_boxplot_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, const char *pen, const char *opt,int l,int lo) @@ -1145,9 +1162,8 @@ void mgl_boxplot_(uintptr_t *gr, uintptr_t *y, const char *pen, const char *opt, void mgl_error_exy(HMGL gr, HCDT x, HCDT y, HCDT ex, HCDT ey, const char *pen, const char *opt) { long i,j,k,m,mx,my,m1,m2,n=ey->GetNx(),pal; - if(x->GetNx()!=n || y->GetNx()!=n || ex->GetNx()!=n ) - { gr->SetWarn(mglWarnDim,"Error"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Error"); return; } + if(mgl_check_dim1(gr,x,y,ey,ex,"Error")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Error",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); @@ -1157,7 +1173,8 @@ void mgl_error_exy(HMGL gr, HCDT x, HCDT y, HCDT ex, HCDT ey, const char *pen, c bool ma = pen && strchr(pen,'@'); char mk = gr->SetPenPal(pen,&pal); - float zVal=gr->Min.z; gr->Reserve(5*n*m); + mreal zVal=gr->AdjustZMin(), vx, vy, ve, vf; + gr->Reserve(5*n*m); if(ma && (mk==0 || !strchr("PXsSdD+xoOC",mk) )) mk = 'S'; long n1,n2,n3,n4; mglPoint q(NAN,NAN); @@ -1171,31 +1188,34 @@ void mgl_error_exy(HMGL gr, HCDT x, HCDT y, HCDT ex, HCDT ey, const char *pen, c { if(strchr("PXsS",mk)) for(i=0;iAddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); - n3 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n4 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); + vx=x->v(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + n1 = gr->AddPnt(mglPoint(vx-ve, vy+vf, zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx-ve, vy-vf, zVal),-1,q,-1,11); + n3 = gr->AddPnt(mglPoint(vx+ve, vy+vf, zVal),-1,q,-1,11); + n4 = gr->AddPnt(mglPoint(vx+ve, vy-vf, zVal),-1,q,-1,11); gr->line_plot(n1,n2); gr->line_plot(n1,n3); gr->line_plot(n4,n2); gr->line_plot(n4,n3); if(sh) gr->NextColor(pal); } if(strchr("dD",mk)) for(i=0;iAddPnt(mglPoint(x->v(i,mx), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); - n3 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); - n4 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); + vx=x->v(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + n1 = gr->AddPnt(mglPoint(vx, vy+vf, zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx-ve, vy, zVal),-1,q,-1,11); + n3 = gr->AddPnt(mglPoint(vx, vy-vf, zVal),-1,q,-1,11); + n4 = gr->AddPnt(mglPoint(vx+ve, vy, zVal),-1,q,-1,11); gr->line_plot(n1,n2); gr->line_plot(n2,n3); gr->line_plot(n3,n4); gr->line_plot(n4,n1); if(sh) gr->NextColor(pal); } if(strchr("oOC",mk)) for(i=0;iv(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); for(k=0,n2=-1;k<=40;k++) { n1 = n2; - n2 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1)*cos(k*M_PI/20), - y->v(i,my)+ey->v(i,m2)*sin(k*M_PI/20), zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx+ve*cos(k*M_PI/20), + vy+vf*sin(k*M_PI/20), zVal),-1,q,-1,11); if(k>0) gr->line_plot(n1,n2); } if(sh) gr->NextColor(pal); @@ -1203,70 +1223,77 @@ void mgl_error_exy(HMGL gr, HCDT x, HCDT y, HCDT ex, HCDT ey, const char *pen, c switch(mk) { case 'P': case '+': for(i=0;iAddPnt(mglPoint(x->v(i,mx), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); - n3 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); - n4 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); - gr->line_plot(n1,n3); gr->line_plot(n2,n4); - if(sh) gr->NextColor(pal); - } break; + { + vx=x->v(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + n1 = gr->AddPnt(mglPoint(vx, vy+vf, zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx-ve, vy, zVal),-1,q,-1,11); + n3 = gr->AddPnt(mglPoint(vx, vy-vf, zVal),-1,q,-1,11); + n4 = gr->AddPnt(mglPoint(vx+ve, vy, zVal),-1,q,-1,11); + gr->line_plot(n1,n3); gr->line_plot(n2,n4); + if(sh) gr->NextColor(pal); + } break; case 'X': case 'x': for(i=0;iAddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); - n3 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n4 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); - gr->line_plot(n1,n3); gr->line_plot(n2,n4); - if(sh) gr->NextColor(pal); - } break; + { + vx=x->v(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + n1 = gr->AddPnt(mglPoint(vx-ve, vy+vf, zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx-ve, vy-vf, zVal),-1,q,-1,11); + n3 = gr->AddPnt(mglPoint(vx+ve, vy+vf, zVal),-1,q,-1,11); + n4 = gr->AddPnt(mglPoint(vx+ve, vy-vf, zVal),-1,q,-1,11); + gr->line_plot(n1,n3); gr->line_plot(n2,n4); + if(sh) gr->NextColor(pal); + } break; case 'S': for(i=0;iAddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); - n3 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n4 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); - gr->quad_plot(n1,n2,n3,n4); - if(sh) gr->NextColor(pal); - } break; + { + vx=x->v(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + n1 = gr->AddPnt(mglPoint(vx-ve, vy+vf, zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx-ve, vy-vf, zVal),-1,q,-1,11); + n3 = gr->AddPnt(mglPoint(vx+ve, vy+vf, zVal),-1,q,-1,11); + n4 = gr->AddPnt(mglPoint(vx+ve, vy-vf, zVal),-1,q,-1,11); + gr->quad_plot(n1,n2,n3,n4); + if(sh) gr->NextColor(pal); + } break; case 'D': for(i=0;iAddPnt(mglPoint(x->v(i,mx), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); - n3 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); - n4 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); - gr->quad_plot(n1,n2,n3,n4); - if(sh) gr->NextColor(pal); - } break; + { + vx=x->v(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + n1 = gr->AddPnt(mglPoint(vx, vy+vf, zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx-ve, vy, zVal),-1,q,-1,11); + n3 = gr->AddPnt(mglPoint(vx, vy-vf, zVal),-1,q,-1,11); + n4 = gr->AddPnt(mglPoint(vx+ve, vy, zVal),-1,q,-1,11); + gr->quad_plot(n1,n2,n3,n4); + if(sh) gr->NextColor(pal); + } break; case 'O': for(i=0;iv(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + n3 = gr->AddPnt(mglPoint(vx,vy,zVal)); + for(k=0,n2=-1;k<=40;k++) { - n3 = gr->AddPnt(mglPoint(x->v(i,mx),y->v(i,my),zVal)); - for(k=0,n2=-1;k<=40;k++) - { - n1 = n2; - n2 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1)*cos(k*M_PI/20), - y->v(i,my)+ey->v(i,m2)*sin(k*M_PI/20), zVal),-1,q,-1,11); - if(k>0) gr->trig_plot(n1,n2,n3); - } - if(sh) gr->NextColor(pal); - } break; - case 'C': for(i=0;imark_plot(gr->AddPnt(mglPoint(x->v(i,mx),y->v(i,my),zVal),-1,q,-1,3), '.'); - if(sh) gr->NextColor(pal); + n1 = n2; + n2 = gr->AddPnt(mglPoint(vx+ve*cos(k*M_PI/20), + vy+vf*sin(k*M_PI/20), zVal),-1,q,-1,11); + if(k>0) gr->trig_plot(n1,n2,n3); } + if(sh) gr->NextColor(pal); + } break; + case 'C': for(i=0;iv(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + gr->mark_plot(gr->AddPnt(mglPoint(vx,vy,zVal),-1,q,-1,3), '.'); + if(sh) gr->NextColor(pal); + } } } else for(i=0;imark_plot(gr->AddPnt(mglPoint(x->v(i,mx),y->v(i,my),zVal)), mk); + vx=x->v(i,mx); ve=ex->v(i,m1); vy=y->v(i,my); vf=ey->v(i,m2); + if(mk) gr->mark_plot(gr->AddPnt(mglPoint(vx,vy,zVal)), mk); - n1 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)+ey->v(i,m2), zVal),-1,q,-1,11); - n2 = gr->AddPnt(mglPoint(x->v(i,mx), y->v(i,my)-ey->v(i,m2), zVal),-1,q,-1,11); + n1 = gr->AddPnt(mglPoint(vx, vy+vf, zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx, vy-vf, zVal),-1,q,-1,11); gr->line_plot(n1,n2); gr->arrow_plot(n1,n2,'I'); gr->arrow_plot(n2,n1,'I'); - n1 = gr->AddPnt(mglPoint(x->v(i,mx)+ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); - n2 = gr->AddPnt(mglPoint(x->v(i,mx)-ex->v(i,m1), y->v(i,my), zVal),-1,q,-1,11); + n1 = gr->AddPnt(mglPoint(vx+ve, vy, zVal),-1,q,-1,11); + n2 = gr->AddPnt(mglPoint(vx-ve, vy, zVal),-1,q,-1,11); gr->line_plot(n1,n2); gr->arrow_plot(n1,n2,'I'); gr->arrow_plot(n2,n1,'I'); if(sh) gr->NextColor(pal); } @@ -1280,6 +1307,7 @@ void mgl_error_xy(HMGL gr, HCDT x, HCDT y, HCDT ey, const char *pen, const char mglData ex(y->GetNx()); ex.Fill(NAN,NAN); mgl_error_exy(gr,x,y,&ex,ey,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_error(HMGL gr, HCDT y, HCDT ey, const char *pen, const char *opt) @@ -1288,6 +1316,7 @@ void mgl_error(HMGL gr, HCDT y, HCDT ey, const char *pen, const char *opt) mglData x(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); mgl_error_xy(gr,&x,y,ey,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_error_(uintptr_t *gr, uintptr_t *y, uintptr_t *ey, const char *pen, const char *opt,int l,int lo) @@ -1310,7 +1339,7 @@ void mgl_error_exy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ex, ui // Chart series // //----------------------------------------------------------------------------- -void face_plot(mglBase *gr, mglPoint o, mglPoint d1, mglPoint d2, float c, bool wire) +void face_plot(mglBase *gr, mglPoint o, mglPoint d1, mglPoint d2, mreal c, bool wire) { const int num=10; mglPoint p,nn=d1^d2; @@ -1362,13 +1391,13 @@ void mgl_chart(HMGL gr, HCDT a, const char *cols, const char *opt) if(cols) for(i=0;iAddTexture(cols[i]); nc++; } - float dy = (gr->Max.y-gr->Min.y)/a->GetNy(), dx, ss, cs, x1, y1, dz=gr->Max.z-gr->Min.z; + mreal dy = (gr->Max.y-gr->Min.y)/a->GetNy(), dx, ss, cs, x1, y1, dz=gr->Max.z-gr->Min.z, vv; mglPoint d1,d2,o; for(j=0;jGetNy();j++) @@ -1379,7 +1408,7 @@ void mgl_chart(HMGL gr, HCDT a, const char *cols, const char *opt) for(cs=0,i=0;iStop) { delete []c; return; } - dx = a->v(i,j)/ss; cc = c[i%nc]; + vv = a->v(i,j); dx = vv/ss; cc = c[i%nc]; if(dx==0) continue; x1 = gr->Min.x + (gr->Max.x-gr->Min.x)*cs/ss; dx *= (gr->Max.x-gr->Min.x); if(cc>=0) @@ -1392,7 +1421,7 @@ void mgl_chart(HMGL gr, HCDT a, const char *cols, const char *opt) face_plot(gr,mglPoint(x1+dx,y1+dy,gr->Max.z),mglPoint(-dx,0,0),mglPoint(0,-dy,0),cc,wire); face_plot(gr,mglPoint(x1+dx,y1+dy,gr->Max.z),mglPoint(0,-dy,0),mglPoint(0,0,-dz),cc,wire); } - cs += a->v(i,j); + cs += vv; } } gr->EndGroup(); delete []c; @@ -1410,9 +1439,8 @@ void mgl_chart_(uintptr_t *gr, uintptr_t *a, const char *col, const char *opt,in void mgl_mark_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT r, const char *pen, const char *opt) { long j,m,mx,my,mz,mr,n=y->GetNx(),pal; - if(x->GetNx()!=n || z->GetNx()!=n || r->GetNx()!=n) - { gr->SetWarn(mglWarnDim,"Mark"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Mark"); return; } + if(mgl_check_dim1(gr,x,y,z,r,"Mark")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Mark",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); @@ -1440,18 +1468,21 @@ void mgl_mark_xy(HMGL gr, HCDT x, HCDT y, HCDT r, const char *pen, const char *o { gr->SaveState(opt); mglData z(y->GetNx()); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_mark_xyz(gr,x,y,&z,r,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_mark_y(HMGL gr, HCDT y, HCDT r, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Mark"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"Mark"); return; } gr->SaveState(opt); - mglData x(y->GetNx()), z(y->GetNx()); + mglData x(n), z(n); x.Fill(gr->Min.x,gr->Max.x); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_mark_xyz(gr,&x,y,&z,r,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_mark_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *r, const char *pen, const char *opt,int l,int lo) @@ -1477,9 +1508,8 @@ void mgl_mark_y_(uintptr_t *gr, uintptr_t *y, uintptr_t *r, const char *pen, con void mgl_tube_xyzr(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT r, const char *pen, const char *opt) { long j,m,mx,my,mz,mr,n=y->GetNx(),pal; - if(n<2) { gr->SetWarn(mglWarnLow,"Tube"); return; } - if(x->GetNx()!=n || z->GetNx()!=n || r->GetNx()!=n) - { gr->SetWarn(mglWarnDim,"Tube"); return; } + if(mgl_check_dim1(gr,x,y,z,r,"Tube")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Tube",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); @@ -1505,7 +1535,7 @@ void mgl_tube_xyzr(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT r, const char *pen, con l = mglPoint(x->dvx(i,mx),y->dvx(i,my),z->dvx(i,mz)); t = !l; t.Normalize(); u = t^l; u.Normalize(); q = mglPoint(x->v(i,mx),y->v(i,my),z->v(i,mz)); - float si,co,ff, rr=r->v(i,mr), dr=r->dvx(i,mr); + mreal si,co,ff, rr=r->v(i,mr), dr=r->dvx(i,mr); for(k=0;kStop) { delete []nn; return; } @@ -1527,48 +1557,55 @@ void mgl_tube_xyr(HMGL gr, HCDT x, HCDT y, HCDT r, const char *pen, const char * { gr->SaveState(opt); mglData z(y->GetNx()); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_tube_xyzr(gr,x,y,&z,r,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tube_r(HMGL gr, HCDT y, HCDT r, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Tube"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"Tube"); return; } gr->SaveState(opt); - mglData x(y->GetNx()), z(y->GetNx()); + mglData x(n), z(n); x.Fill(gr->Min.x,gr->Max.x); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_tube_xyzr(gr,&x,y,&z,r,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_tube(HMGL gr, HCDT y, float rr, const char *pen, const char *opt) +void mgl_tube(HMGL gr, HCDT y, mreal rr, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Tube"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"Tube"); return; } gr->SaveState(opt); - mglData x(y->GetNx()), r(y->GetNx()), z(y->GetNx()); + mglData x(n), r(n), z(n); x.Fill(gr->Min.x,gr->Max.x); r.Fill(rr,rr); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_tube_xyzr(gr,&x,y,&z,&r,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_tube_xy(HMGL gr, HCDT x, HCDT y, float rr, const char *pen, const char *opt) +void mgl_tube_xy(HMGL gr, HCDT x, HCDT y, mreal rr, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Tube"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"Tube"); return; } gr->SaveState(opt); - mglData r(y->GetNx()), z(y->GetNx()); + mglData r(n), z(n); r.Fill(rr,rr); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_tube_xyzr(gr,x,y,&z,&r,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_tube_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, float rr, const char *pen, const char *opt) +void mgl_tube_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, mreal rr, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Tube"); return; } gr->SaveState(opt); mglData r(y->GetNx()); r.Fill(rr,rr); mgl_tube_xyzr(gr,x,y,z,&r,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tube_xyzr_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *r, const char *pen, const char *opt,int l,int lo) @@ -1587,17 +1624,17 @@ void mgl_tube_r_(uintptr_t *gr, uintptr_t *y, uintptr_t *r, const char *pen, con char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_tube_r(_GR_,_DA_(y),_DA_(r),s,o); delete []s; delete []o; } //----------------------------------------------------------------------------- -void mgl_tube_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, float *r, const char *pen, const char *opt,int l,int lo) +void mgl_tube_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, mreal *r, const char *pen, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,pen,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_tube_xyz(_GR_,_DA_(x),_DA_(y),_DA_(z),*r,s,o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_tube_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, float *r, const char *pen, const char *opt,int l,int lo) +void mgl_tube_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, mreal *r, const char *pen, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,pen,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_tube_xy(_GR_,_DA_(x),_DA_(y),*r,s,o); delete []s; delete []o; } //----------------------------------------------------------------------------- -void mgl_tube_(uintptr_t *gr, uintptr_t *y, float *r, const char *pen, const char *opt,int l,int lo) +void mgl_tube_(uintptr_t *gr, uintptr_t *y, mreal *r, const char *pen, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,pen,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_tube(_GR_,_DA_(y),*r,s,o); @@ -1610,10 +1647,10 @@ void mgl_tube_(uintptr_t *gr, uintptr_t *y, float *r, const char *pen, const cha void mgl_tape_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char *opt) { long j,m,mx,my,mz,n=y->GetNx(),pal; - if(x->GetNx()!=n || z->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Tape"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Tape"); return; } + if(mgl_check_dim1(gr,x,y,z,0,"Tape")) return; + static int cgid=1; gr->StartGroup("Tape",cgid++); - float ll, rr = gr->SaveState(opt); + mreal ll, rr = gr->SaveState(opt); if(rr==0 || mgl_isnan(rr)) rr = mgl_norm(gr->Max-gr->Min)*gr->BarWidth/25; m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; gr->SetPenPal(pen,&pal); gr->Reserve(4*n*m); @@ -1621,7 +1658,7 @@ void mgl_tape_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char * long n1=-1,n2=-1,n3=-1,n4=-1, m1=-1,m2=-1,m3=-1,m4=-1; bool sh = pen && strchr(pen,'!'), xo = pen && strchr(pen,'x'), zo = pen && strchr(pen,'z'), wire = pen && strchr(pen,'#'); if(!xo && !zo) xo = zo = true; - float c1,c2; + mreal c1,c2; for(j=0;jAddPnt(p2,c1,q2,-1,3); n2 = gr->AddPnt(p2+rr*q1,c1,q2,-1,3); } - if(zo) { n3 = gr->AddPnt(p2,c2,q1,-1,3); n4 = gr->AddPnt(p2+rr*q2,c2,q1,-1,3); } + if(p2>gr->Min && p2Max) + { + if(xo) { n1 = gr->AddPnt(p2,c1,q2,-1,3); n2 = gr->AddPnt(p2+rr*q1,c1,q2,-1,3); } + if(zo) { n3 = gr->AddPnt(p2,c2,q1,-1,3); n4 = gr->AddPnt(p2+rr*q2,c2,q1,-1,3); } + } + else { n1=n2=n3=n4=-1; } register long i; for(i=1;igr->Min && p2Max) { - n1 = gr->AddPnt(p2,c1,wire?qn:q2,-1,3); - n2 = gr->AddPnt(p2+rr*q1,c1,wire?qn:q2,-1,3); - if(wire) gr->line_plot(m2,n2); - else gr->quad_plot(n1,n2,m1,m2); - } - if(zo) - { - n3 = gr->AddPnt(p2,c2,wire?qn:q1,-1,3); - n4 = gr->AddPnt(p2+rr*q2,c2,wire?qn:q1,-1,3); - if(wire) gr->line_plot(m4,n4); - else gr->quad_plot(n3,n4,m3,m4); + if(xo) + { + n1 = gr->AddPnt(p2,c1,wire?qn:q2,-1,3); + n2 = gr->AddPnt(p2+rr*q1,c1,wire?qn:q2,-1,3); + if(wire) gr->line_plot(m2,n2); + else gr->quad_plot(n1,n2,m1,m2); + } + if(zo) + { + n3 = gr->AddPnt(p2,c2,wire?qn:q1,-1,3); + n4 = gr->AddPnt(p2+rr*q2,c2,wire?qn:q1,-1,3); + if(wire) gr->line_plot(m4,n4); + else gr->quad_plot(n3,n4,m3,m4); + } } if(sh) c2=c1=gr->NextColor(pal); } @@ -1668,18 +1712,21 @@ void mgl_tape_xy(HMGL gr, HCDT x, HCDT y, const char *pen, const char *opt) { gr->SaveState(opt); mglData z(y->GetNx()); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_tape_xyz(gr,x,y,&z,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tape(HMGL gr, HCDT y, const char *pen, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"Plot"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"Plot"); return; } gr->SaveState(opt); - mglData x(y->GetNx()), z(y->GetNx()); + mglData x(n), z(n); x.Fill(gr->Min.x,gr->Max.x); - z.Fill(gr->Min.z,gr->Min.z); + mreal zm = gr->AdjustZMin(); z.Fill(zm,zm); mgl_tape_xyz(gr,&x,y,&z,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tape_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *pen, const char *opt,int l,int lo) diff --git a/src/prc.cpp b/src/prc.cpp index 3074d10..9969922 100644 --- a/src/prc.cpp +++ b/src/prc.cpp @@ -17,25 +17,22 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include #include #include -#include #include "mgl2/canvas.h" #include "mgl2/canvas_cf.h" -#include "oPRCFile.h" +#include "prc/oPRCFile.h" #include #include #include #include #include #include -#include #if MGL_HAVE_PDF -#include #include -#include #include #include #include @@ -55,22 +52,25 @@ struct prctriangle { }; //----------------------------------------------------------------------------- struct prctriangles { - prctriangles(const HMGL g) : samecolour(true), colourset(false), - gr(g), ntxt(g->GetTxtNum()) {} + prctriangles(const HMGL g) : samecolour(true), samealpha(true), + gr(g), ntxt(g->GetTxtNum()), vertexcolor(g->get(MGL_PREFERVC)) {} std::map points; std::map texturecoords; + std::map colours; std::vector triangles; - RGBAColour colour; + RGBAColour commoncolour; bool samecolour; - bool colourset; + float commonalpha; + bool samealpha; const HMGL gr; const size_t ntxt; - - + bool vertexcolor; + + uint32_t addPoint(const mglPnt& p) { const PRCVector3d point(p.x,p.y,p.z); - + std::map::iterator pPoint = points.find(point); if(pPoint!=points.end()) return pPoint->second; @@ -81,11 +81,11 @@ struct prctriangles { return point_index; } } - + uint32_t addPoint(float x, float y, float z) { const PRCVector3d point(x,y,z); - + std::map::iterator pPoint = points.find(point); if(pPoint!=points.end()) return pPoint->second; @@ -96,7 +96,7 @@ struct prctriangles { return point_index; } } - + void writePoints(double (*P)[3]) { for(std::map::const_iterator pPoint = points.begin(); pPoint != points.end(); pPoint++) @@ -106,46 +106,69 @@ struct prctriangles { P[pPoint->second][2] = pPoint->first.z; } } - - uint32_t addTextureCoords(const mglPnt& p) + + uint32_t addColourInfo(const mglPnt& p) { - const float u = ((1-p.ta)*(512-2)+1)/512; - const float v = ((1-p.c/ntxt)*(512*ntxt-2) + 1)/(512*ntxt); - - const PRCVector2d point(u, v); - - if (colourset) { - if (samecolour) { - if (colour.R != p.r || colour.G != p.g || colour.B != p.b || colour.A != p.a) - samecolour = false; + const RGBAColour colour(p.r,p.g,p.b,p.a); + + if (colours.empty() && texturecoords.empty()) { + commoncolour = colour; + commonalpha = p.a; + } + if (samecolour) { + if (commoncolour != colour) + samecolour = false; + } + if (samealpha) { + if (commonalpha != p.a) + samealpha = false; + } + + if (vertexcolor) { + std::map::iterator pColour = colours.find(colour); + if(pColour!=colours.end()) + return pColour->second; + else + { + const uint32_t colour_index = colours.size(); + colours.insert(std::make_pair(colour,colour_index)); + return colour_index; + } + } else { + const float u = p.ta; + const float v = 1 - p.c/ntxt; + + const PRCVector2d point(u, v); + std::map::iterator pPoint = texturecoords.find(point); + if(pPoint!=texturecoords.end()) + return pPoint->second; + else + { + const uint32_t point_index = texturecoords.size(); + texturecoords.insert(std::make_pair(point,point_index)); + return point_index; } } - else { - colour.Set(p.r, p.g, p.b, p.a); - colourset = true; - } - - - std::map::iterator pPoint = texturecoords.find(point); - if(pPoint!=texturecoords.end()) - return pPoint->second; - else + } + + void writeTextureCoords(double (*T)[2]) + { + for(std::map::const_iterator pPoint = texturecoords.begin(); pPoint != texturecoords.end(); pPoint++) { - const uint32_t point_index = texturecoords.size(); - texturecoords.insert(std::make_pair(point,point_index)); - return point_index; + T[pPoint->second][0] = pPoint->first.x; + T[pPoint->second][1] = pPoint->first.y; } } - - void writeTextureCoords(double (*P)[2]) + + void writeColours(RGBAColour *C) { - for(std::map::const_iterator pPoint = texturecoords.begin(); pPoint != texturecoords.end(); pPoint++) + for(std::map::const_iterator pColour = colours.begin(); pColour != colours.end(); pColour++) { - P[pPoint->second][0] = pPoint->first.x; - P[pPoint->second][1] = pPoint->first.y; + C[pColour->second] = pColour->first; } } }; + //----------------------------------------------------------------------------- /* structure to store PNG image bytes */ struct png_buf @@ -158,29 +181,28 @@ void my_png_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { struct png_buf* p=(struct png_buf*)png_get_io_ptr(png_ptr); size_t nsize = p->size + length; - + /* allocate or grow buffer */ if(p->data) p->data = (uint8_t*)realloc(p->data, nsize); else p->data = (uint8_t*)malloc(nsize); - + if(!p->data) png_error(png_ptr, "Write Error - no mem"); - + /* copy new bytes to end of buffer */ memcpy(p->data + p->size, data, length); p->size += length; } //----------------------------------------------------------------------------- -void my_png_flush(png_structp png_ptr) +void my_png_flush(png_structp /*png_ptr*/) { } //----------------------------------------------------------------------------- -void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) +void mgl_write_prc(HMGL gr, const char *fname,const char */*descr*/, int make_pdf) { if(gr->GetPrmNum()<=0) return; // nothing to do -// register size_t i,j; { long m1=0,m2=0,m; for(size_t i=0;iGrp.size();i++) // prepare array of indirect indexing @@ -204,11 +226,23 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) oPRCFile file(tname); PRCoptions grpopt; grpopt.tess = true; - grpopt.closed = false; // set to true to make only front side visible - // grpopt.no_break = true; - // grpopt.do_break = false; + grpopt.closed = gr->get(MGL_ONESIDED); // set to true to make only front side visible + // grpopt.no_break = true; + // grpopt.do_break = false; + grpopt.crease_angle = 80; uint32_t materialMathGLid = m1; + if (gr->get(MGL_PREFERVC)) { + const PRCmaterial materialMathGL( + RGBAColour(0.1,0.1,0.1,1), // ambient + RGBAColour(1.0,1.0,1.0,1), // diffuse + RGBAColour(0.1,0.1,0.1,1), // emissive + RGBAColour(0.0,0.0,0.0,1), // spectral + 1.0,0.1 // alpha, shininess + ); + materialMathGLid = file.addMaterial(materialMathGL); + } + else { png_buf buffer; buffer.data = (uint8_t*)malloc(1024);; @@ -219,8 +253,10 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) const png_uint_32 width=256, height=256*ntxt; png_bytep buf = new png_byte[4*width*height]; png_bytepp pbuf= new png_bytep[height]; - for(size_t i=0;iGetTxt(i).GetRGBA(buf+i*256*256*4); + for(size_t i=0;iGetTxt(i).GetRGBA(buf+i*256*256*4); png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0); png_infop info_ptr = png_create_info_struct(png_ptr); @@ -229,11 +265,11 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) png_set_filter(png_ptr, 0, PNG_ALL_FILTERS); png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); png_set_IHDR(png_ptr, info_ptr, width, height, 8, - PNG_COLOR_TYPE_RGB_ALPHA, + PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_set_rows(png_ptr, info_ptr, pbuf); - png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, 0); + png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, 0); png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); @@ -241,8 +277,8 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) const PRCmaterial materialMathGL( RGBAColour(0.1,0.1,0.1,1), // ambient RGBAColour(1.0,1.0,1.0,1), // diffuse - RGBAColour(0.1,0.1,0.1,1), //emissive - RGBAColour(0.0,0.0,0.0,1), //spectral + RGBAColour(0.1,0.1,0.1,1), // emissive + RGBAColour(0.0,0.0,0.0,1), // spectral 1.0,0.1, // alpha, shininess buffer.data, KEPRCPicture_PNG, 0, 0, buffer.size, true); materialMathGLid = file.addMaterial(materialMathGL); @@ -252,9 +288,13 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) // primitive definition in groups mglPnt p0; - p0.x = dynamic_cast(gr)->GetWidth()/2.; - p0.y = dynamic_cast(gr)->GetHeight()/2.; - p0.z = sqrt(p0.x*p0.y); + const double width = dynamic_cast(gr)->GetWidth(); + const double height = dynamic_cast(gr)->GetHeight(); + const double depth = sqrt(width*height); + + p0.x = width/2.; + p0.y = height/2.; + p0.z = (1.f-sqrt(width*height)/(2*depth))*depth; for(size_t i=0;iGrp.size();i++) { @@ -354,7 +394,7 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) break; case 'S': { - const uint32_t ti = group.addTextureCoords(p); + const uint32_t ti = group.addColourInfo(p); const uint32_t pi1 = group.addPoint(p.x-ss,p.y-ss,p.z); const uint32_t pi2 = group.addPoint(p.x+ss,p.y-ss,p.z); @@ -393,7 +433,7 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) break; case 'D': { - const uint32_t ti = group.addTextureCoords(p); + const uint32_t ti = group.addColourInfo(p); const uint32_t pi1 = group.addPoint(p.x,p.y-ss,p.z); const uint32_t pi2 = group.addPoint(p.x+ss,p.y,p.z); @@ -472,7 +512,7 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) break; case 'T': { - const uint32_t ti = group.addTextureCoords(p); + const uint32_t ti = group.addColourInfo(p); const uint32_t pi1 = group.addPoint(p.x-ss,p.y-ss/2,p.z); const uint32_t pi2 = group.addPoint(p.x+ss,p.y-ss/2,p.z); @@ -502,7 +542,7 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) break; case 'V': { - const uint32_t ti = group.addTextureCoords(p); + const uint32_t ti = group.addColourInfo(p); const uint32_t pi1 = group.addPoint(p.x-ss,p.y+ss/2,p.z); const uint32_t pi2 = group.addPoint(p.x,p.y-ss,p.z); @@ -532,7 +572,7 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) break; case 'L': { - const uint32_t ti = group.addTextureCoords(p); + const uint32_t ti = group.addColourInfo(p); const uint32_t pi1 = group.addPoint(p.x+ss/2,p.y+ss,p.z); const uint32_t pi2 = group.addPoint(p.x-ss, p.y, p.z); @@ -562,7 +602,7 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) break; case 'R': { - const uint32_t ti = group.addTextureCoords(p); + const uint32_t ti = group.addColourInfo(p); const uint32_t pi1 = group.addPoint(p.x-ss/2,p.y+ss,p.z); const uint32_t pi2 = group.addPoint(p.x-ss/2,p.y-ss,p.z); @@ -592,7 +632,7 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) break; case 'O': { - const uint32_t ti = group.addTextureCoords(p); + const uint32_t ti = group.addColourInfo(p); const uint32_t cpi=group.addPoint(p); uint32_t pi[21]; @@ -654,9 +694,9 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) triangle.pi[0] = group.addPoint(p1); triangle.pi[1] = group.addPoint(p2); triangle.pi[2] = group.addPoint(p3); - triangle.ti[0] = group.addTextureCoords(p1); - triangle.ti[1] = group.addTextureCoords(p2); - triangle.ti[2] = group.addTextureCoords(p3); + triangle.ti[0] = group.addColourInfo(p1); + triangle.ti[1] = group.addColourInfo(p2); + triangle.ti[2] = group.addColourInfo(p3); group.triangles.push_back(triangle); } break; @@ -664,19 +704,19 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) { const mglPnt p1 = gr->GetPnt(q.n1) - p0; const uint32_t pi1 = group.addPoint(p1); - const uint32_t ti1 = group.addTextureCoords(p1); + const uint32_t ti1 = group.addColourInfo(p1); const mglPnt p2 = gr->GetPnt(q.n2) - p0; const uint32_t pi2 = group.addPoint(p2); - const uint32_t ti2 = group.addTextureCoords(p2); + const uint32_t ti2 = group.addColourInfo(p2); const mglPnt p3 = gr->GetPnt(q.n3) - p0; const uint32_t pi3 = group.addPoint(p3); - const uint32_t ti3 = group.addTextureCoords(p3); + const uint32_t ti3 = group.addColourInfo(p3); const mglPnt p4 = gr->GetPnt(q.n4) - p0; const uint32_t pi4 = group.addPoint(p4); - const uint32_t ti4 = group.addTextureCoords(p4); + const uint32_t ti4 = group.addColourInfo(p4); prctriangle triangle1, triangle2; triangle1.pi[0] = pi1; @@ -712,29 +752,58 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) PI[i][2] = group.triangles[i].pi[2]; } if (!group.samecolour) { - const uint32_t nT = group.texturecoords.size(); - double (*T)[2] = new double[nT][2]; - group.writeTextureCoords(T); - uint32_t (*TI)[3] = new uint32_t[nI][3]; - for(uint32_t i = 0; iget(MGL_PREFERVC)) { + const uint32_t nC = group.colours.size(); + RGBAColour *C = new RGBAColour[nC]; + group.writeColours(C); + uint32_t (*CI)[3] = new uint32_t[nI][3]; + for(uint32_t i = 0; i(gr)->GetWidth(); + const HPDF_REAL width = dynamic_cast(gr)->GetWidth(); const HPDF_REAL height = dynamic_cast(gr)->GetHeight(); - const HPDF_REAL depth = sqrt(width*height); + const HPDF_REAL depth = sqrt(width*height); const HPDF_Rect rect = {0, 0, width, height}; @@ -792,6 +861,10 @@ void mgl_write_prc(HMGL gr, const char *fname,const char *descr, int make_pdf) // Create annotation annot = HPDF_Page_Create3DAnnot (page, rect, u3d ); + // Enable toolbar + HPDF_Dict action = (HPDF_Dict)HPDF_Dict_GetItem (annot, "3DA", HPDF_OCLASS_DICT); + HPDF_Dict_AddBoolean (action, "TB", HPDF_TRUE); + /* save the document to a file */ const size_t len = strlen(tname); tname[len-2]='p'; tname[len-2]='d'; tname[len-1]='f'; diff --git a/src/prc/oPRCFile.cc b/src/prc/oPRCFile.cc index d300aae..2a7dcc8 100644 --- a/src/prc/oPRCFile.cc +++ b/src/prc/oPRCFile.cc @@ -478,6 +478,7 @@ void oPRCFile::doGroup(PRCgroup& group) } map points; PRC3DTess *tess = new PRC3DTess(); + tess->crease_angle = group.options.crease_angle; PRCTessFace *tessFace = new PRCTessFace(); tessFace->used_entities_flag=PRC_FACETESSDATA_Triangle; uint32_t triangles = 0; @@ -539,6 +540,7 @@ void oPRCFile::doGroup(PRCgroup& group) { map points; PRC3DTess *tess = new PRC3DTess(); + tess->crease_angle = group.options.crease_angle; PRCTessFace *tessFace = new PRCTessFace(); tessFace->used_entities_flag=PRC_FACETESSDATA_Triangle; uint32_t triangles = 0; @@ -696,6 +698,7 @@ void oPRCFile::doGroup(PRCgroup& group) { for(std::vector::iterator pit=group.polymodels.begin(); pit!=group.polymodels.end(); pit++) { + (*pit)->is_closed = group.options.closed; part_definition->addPolyBrepModel(*pit); } } @@ -1547,11 +1550,11 @@ void oPRCFile::addTriangles(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t nN, const double N[][3], const uint32_t NI[][3], uint32_t nT, const double T[][2], const uint32_t TI[][3], uint32_t nC, const RGBAColour C[], const uint32_t CI[][3], - uint32_t nM, const PRCmaterial M[], const uint32_t MI[]) + uint32_t nM, const PRCmaterial M[], const uint32_t MI[], double ca) { if(nP==0 || P==NULL || nI==0 || PI==NULL) return; - const uint32_t tess_index = createTriangleMesh(nP, P, nI, PI, m, nN, N, NI, nT, T, TI, nC, C, CI, nM, M, MI); + const uint32_t tess_index = createTriangleMesh(nP, P, nI, PI, m, nN, N, NI, nT, T, TI, nC, C, CI, nM, M, MI, ca); useMesh(tess_index,m1); } @@ -1559,7 +1562,7 @@ uint32_t oPRCFile::createTriangleMesh(uint32_t nP, const double P[][3], uint32_t uint32_t nN, const double N[][3], const uint32_t NI[][3], uint32_t nT, const double T[][2], const uint32_t TI[][3], uint32_t nC, const RGBAColour C[], const uint32_t CI[][3], - uint32_t nS, const uint32_t S[], const uint32_t SI[]) + uint32_t nS, const uint32_t S[], const uint32_t SI[], double ca) { if(nP==0 || P==NULL || nI==0 || PI==NULL) return m1; @@ -1590,6 +1593,8 @@ uint32_t oPRCFile::createTriangleMesh(uint32_t nP, const double P[][3], uint32_t tess->normal_coordinate.push_back(N[i][2]); } } + else + tess->crease_angle = ca; if(textured) { tess->texture_coordinate.reserve(2*nT); @@ -1668,11 +1673,11 @@ void oPRCFile::addQuads(uint32_t nP, const double P[][3], uint32_t nI, const uin uint32_t nN, const double N[][3], const uint32_t NI[][4], uint32_t nT, const double T[][2], const uint32_t TI[][4], uint32_t nC, const RGBAColour C[], const uint32_t CI[][4], - uint32_t nM, const PRCmaterial M[], const uint32_t MI[]) + uint32_t nM, const PRCmaterial M[], const uint32_t MI[], double ca) { if(nP==0 || P==NULL || nI==0 || PI==NULL) return; - const uint32_t tess_index = createQuadMesh(nP, P, nI, PI, m, nN, N, NI, nT, T, TI, nC, C, CI, nM, M, MI); + const uint32_t tess_index = createQuadMesh(nP, P, nI, PI, m, nN, N, NI, nT, T, TI, nC, C, CI, nM, M, MI, ca); useMesh(tess_index,m1); } @@ -1680,7 +1685,7 @@ uint32_t oPRCFile::createQuadMesh(uint32_t nP, const double P[][3], uint32_t nI, uint32_t nN, const double N[][3], const uint32_t NI[][4], uint32_t nT, const double T[][2], const uint32_t TI[][4], uint32_t nC, const RGBAColour C[], const uint32_t CI[][4], - uint32_t nS, const uint32_t S[], const uint32_t SI[]) + uint32_t nS, const uint32_t S[], const uint32_t SI[], double ca) { if(nP==0 || P==NULL || nI==0 || PI==NULL) return m1; @@ -1711,6 +1716,8 @@ uint32_t oPRCFile::createQuadMesh(uint32_t nP, const double P[][3], uint32_t nI, tess->normal_coordinate.push_back(N[i][2]); } } + else + tess->crease_angle = ca; if(textured) { tess->texture_coordinate.reserve(2*nT); diff --git a/src/prc/oPRCFile.h b/src/prc/oPRCFile.h index 25906ff..ca3d58e 100644 --- a/src/prc/oPRCFile.h +++ b/src/prc/oPRCFile.h @@ -435,11 +435,12 @@ public: bool tess; // use tessellated mesh to store straight patches bool do_break; // bool no_break; // do not render transparent patches as one-faced nodes + double crease_angle; // crease angle for meshes PRCoptions(double compression=0.0, double granularity=0.0, bool closed=false, - bool tess=false, bool do_break=true, bool no_break=false) + bool tess=false, bool do_break=true, bool no_break=false, double crease_angle=25.8419) : compression(compression), granularity(granularity), closed(closed), - tess(tess), do_break(do_break), no_break(no_break) {} + tess(tess), do_break(do_break), no_break(no_break), crease_angle(crease_angle) {} }; class PRCgroup @@ -742,17 +743,17 @@ class oPRCFile uint32_t nN, const double N[][3], const uint32_t NI[][3], uint32_t nT, const double T[][2], const uint32_t TI[][3], uint32_t nC, const RGBAColour C[], const uint32_t CI[][3], - uint32_t nM, const PRCmaterial M[], const uint32_t MI[]); + uint32_t nM, const PRCmaterial M[], const uint32_t MI[], double ca); uint32_t createTriangleMesh(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t PI[][3], uint32_t style_index, uint32_t nN, const double N[][3], const uint32_t NI[][3], uint32_t nT, const double T[][2], const uint32_t TI[][3], uint32_t nC, const RGBAColour C[], const uint32_t CI[][3], - uint32_t nS, const uint32_t S[], const uint32_t SI[]); + uint32_t nS, const uint32_t S[], const uint32_t SI[], double ca); uint32_t createTriangleMesh(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t PI[][3], const PRCmaterial& m, uint32_t nN, const double N[][3], const uint32_t NI[][3], uint32_t nT, const double T[][2], const uint32_t TI[][3], uint32_t nC, const RGBAColour C[], const uint32_t CI[][3], - uint32_t nM, const PRCmaterial M[], const uint32_t MI[]) + uint32_t nM, const PRCmaterial M[], const uint32_t MI[], double ca) { const uint32_t style = addMaterial(m); if(M!=NULL && nM>0) @@ -760,28 +761,28 @@ class oPRCFile uint32_t* const styles = new uint32_t[nM]; for(uint32_t i=0; i0) @@ -789,12 +790,12 @@ class oPRCFile uint32_t* const styles = new uint32_t[nM]; for(uint32_t i=0; i -#include #include "mgl2/canvas.h" #include "mgl2/prim.h" #include "mgl2/data.h" @@ -27,28 +25,26 @@ // Mark & Curve series // //----------------------------------------------------------------------------- -void mgl_mark(HMGL gr, float x,float y,float z,const char *mark) +void mgl_mark(HMGL gr, mreal x,mreal y,mreal z,const char *mark) { char mk = gr->SetPenPal(mark); if(!mk) mk = '.'; - mglPoint p(x,y,z); - gr->mark_plot(gr->AddPnt(p,gr->CDef,mglPoint(NAN),-1,3),mk); + gr->mark_plot(gr->AddPnt(mglPoint(x,y,z),gr->CDef,mglPoint(NAN),-1,3),mk); } //----------------------------------------------------------------------------- void mgl_mark_(uintptr_t *gr, mreal *x, mreal *y, mreal *z, const char *pen,int l) { char *s=new char[l+1]; memcpy(s,pen,l); s[l]=0; mgl_mark(_GR_, *x,*y,*z,s); delete []s; } //----------------------------------------------------------------------------- -void mgl_ball(HMGL gr, float x,float y,float z) +void mgl_ball(HMGL gr, mreal x,mreal y,mreal z) { - mglPoint p(x,y,z); - gr->mark_plot(gr->AddPnt(p,gr->AddTexture('r'),mglPoint(NAN),-1,3),'.'); + gr->mark_plot(gr->AddPnt(mglPoint(x,y,z),gr->AddTexture('r'),mglPoint(NAN),-1,3),'.'); } //----------------------------------------------------------------------------- void mgl_ball_(uintptr_t *gr, mreal *x,mreal *y,mreal *z) { mgl_ball(_GR_, *x,*y,*z); } //----------------------------------------------------------------------------- -void mgl_line(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, const char *pen,int n) +void mgl_line(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, const char *pen,int n) { static int cgid=1; gr->StartGroup("Line",cgid++); if(mgl_isnan(z1) || mgl_isnan(z2)) z1=z2=gr->Min.z; @@ -57,13 +53,13 @@ void mgl_line(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z n = (n<2) ? 2 : n; register long i,k1,k2; - register float s; + register mreal s; gr->Reserve(n); k1 = gr->AddPnt(p,gr->CDef,nn,-1,3); for(i=1;iStop) return; - s = i/float(n-1); p = p1*(1-s)+p2*s; k2 = k1; + s = i/mreal(n-1); p = p1*(1-s)+p2*s; k2 = k1; k1 = gr->AddPnt(p,gr->CDef,nn,-1,3); gr->line_plot(k2,k1); if(i==1) gr->arrow_plot(k2,k1,gr->Arrow1); @@ -76,7 +72,7 @@ void mgl_line_(uintptr_t *gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal { char *s=new char[l+1]; memcpy(s,pen,l); s[l]=0; mgl_line(_GR_, *x1,*y1,*z1, *x2,*y2,*z2,s,*n); delete []s; } //----------------------------------------------------------------------------- -void mgl_curve(HMGL gr, float x1, float y1, float z1, float dx1, float dy1, float dz1, float x2, float y2, float z2, float dx2, float dy2, float dz2, const char *pen,int n) +void mgl_curve(HMGL gr, mreal x1, mreal y1, mreal z1, mreal dx1, mreal dy1, mreal dz1, mreal x2, mreal y2, mreal z2, mreal dx2, mreal dy2, mreal dz2, const char *pen,int n) { static int cgid=1; gr->StartGroup("Curve",cgid++); mglPoint p1(x1,y1,z1), p2(x2,y2,z2), d1(dx1,dy1,dz1), d2(dx2,dy2,dz2), a,b,p=p1,nn=mglPoint(NAN); @@ -85,7 +81,7 @@ void mgl_curve(HMGL gr, float x1, float y1, float z1, float dx1, float dy1, floa gr->SetPenPal(pen); register long i,k1,k2; - register float s; + register mreal s; gr->Reserve(n); k1=gr->AddPnt(p,gr->CDef,nn,-1,3); for(i=0;iStartGroup("ErBox",cgid++); char mk=gr->SetPenPal(pen); @@ -132,12 +128,12 @@ void mgl_error_box_(uintptr_t *gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, m // Face series // //----------------------------------------------------------------------------- -void mgl_face(HMGL gr, float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, const char *stl) +void mgl_face(HMGL gr, mreal x0, mreal y0, mreal z0, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal x3, mreal y3, mreal z3, const char *stl) { static int cgid=1; gr->StartGroup("Face",cgid++); long pal; gr->SetPenPal(stl,&pal); - float c1,c2,c3,c4,zz=(gr->Min.z+gr->Max.z)/2; + mreal c1,c2,c3,c4,zz=(gr->Min.z+gr->Max.z)/2; c1=c2=c3=c4=gr->CDef; if(mgl_isnan(z0)) z0 = zz; if(mgl_isnan(z1)) z1 = zz; if(mgl_isnan(z2)) z2 = zz; if(mgl_isnan(z3)) z3 = zz; @@ -165,13 +161,13 @@ void mgl_face(HMGL gr, float x0, float y0, float z0, float x1, float y1, float z gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_facex(HMGL gr, float x0, float y0, float z0, float wy, float wz, const char *stl, float d1, float d2) +void mgl_facex(HMGL gr, mreal x0, mreal y0, mreal z0, mreal wy, mreal wz, const char *stl, mreal d1, mreal d2) { mgl_face(gr, x0,y0,z0, x0,y0+wy,z0, x0,y0,z0+wz, x0,y0+wy+d1,z0+wz+d2, stl); } //----------------------------------------------------------------------------- -void mgl_facey(HMGL gr, float x0, float y0, float z0, float wx, float wz, const char *stl, float d1, float d2) +void mgl_facey(HMGL gr, mreal x0, mreal y0, mreal z0, mreal wx, mreal wz, const char *stl, mreal d1, mreal d2) { mgl_face(gr, x0,y0,z0, x0+wx,y0,z0, x0,y0,z0+wz, x0+wx+d1,y0,z0+wz+d2, stl); } //----------------------------------------------------------------------------- -void mgl_facez(HMGL gr, float x0, float y0, float z0, float wx, float wy, const char *stl, float d1, float d2) +void mgl_facez(HMGL gr, mreal x0, mreal y0, mreal z0, mreal wx, mreal wy, const char *stl, mreal d1, mreal d2) { mgl_face(gr, x0,y0,z0, x0,y0+wy,z0, x0+wx,y0,z0, x0+wx+d1,y0+wy+d2,z0, stl); } //----------------------------------------------------------------------------- void mgl_facex_(uintptr_t* gr, mreal *x0, mreal *y0, mreal *z0, mreal *wy, mreal *wz, const char *stl, mreal *dx, mreal *dy, int l) @@ -187,7 +183,7 @@ void mgl_facez_(uintptr_t* gr, mreal *x0, mreal *y0, mreal *z0, mreal *wx, mreal { char *s=new char[l+1]; memcpy(s,stl,l); s[l]=0; mgl_facez(_GR_, *x0,*y0,*z0,*wx,*wy,s,*dx,*dy); delete []s; } //----------------------------------------------------------------------------- -void mgl_face_(uintptr_t* gr, float *x0, float *y0, float *z0, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, float *x3, float *y3, float *z3, const char *stl, int l) +void mgl_face_(uintptr_t* gr, mreal *x0, mreal *y0, mreal *z0, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, mreal *x3, mreal *y3, mreal *z3, const char *stl, int l) { char *s=new char[l+1]; memcpy(s,stl,l); s[l]=0; mgl_face(_GR_, *x0,*y0,*z0, *x1,*y1,*z1, *x2,*y2,*z2, *x3,*y3,*z3, stl); delete []s; } //----------------------------------------------------------------------------- @@ -195,7 +191,7 @@ void mgl_face_(uintptr_t* gr, float *x0, float *y0, float *z0, float *x1, float // Cone // //----------------------------------------------------------------------------- -void mgl_cone(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2, const char *stl) +void mgl_cone(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal r1, mreal r2, const char *stl) { if(r2<0) r2=r1; if(r1==0 && r2==0) return; @@ -204,7 +200,7 @@ void mgl_cone(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z mglPoint p1(x1,y1,z1), p2(x2,y2,z2), p,q, d=p2-p1,a,b; a=!d; a.Normalize(); b=d^a; b.Normalize(); long ss=gr->AddTexture(stl); - float c1=gr->GetC(ss,p1.z), c2=gr->GetC(ss,p2.z); + mreal c1=gr->GetC(ss,p1.z), c2=gr->GetC(ss,p2.z); long *kk=new long[164],k1=-1,k2=-1; bool edge = stl && strchr(stl,'@'); bool wire = stl && strchr(stl,'#'); @@ -214,7 +210,7 @@ void mgl_cone(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z k1=gr->AddPnt(p1,c1,d,-1,3); k2=gr->AddPnt(p2,c2,d,-1,3); } - float f,si,co, dr=r2-r1; + mreal f,si,co, dr=r2-r1; register long i; for(i=0;i<(wire?13:41);i++) { @@ -260,45 +256,46 @@ void mgl_cone_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal //----------------------------------------------------------------------------- void mgl_cones_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *pen, const char *opt) { - long i,j,m,mx,my,mz,n=z->GetNx(),nx=x->GetNx(), pal; - if(x->GetNx()GetNx()SetWarn(mglWarnDim,"Cones"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Cones"); return; } + long i,j,m,mx,my,mz,n=z->GetNx(),nx=x->GetNx(), nz=z->GetNy(), pal; + if(mgl_check_dim1(gr,x,z,y,0,"Cones",true)) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Cones",cgid++); - m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; + m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = nz > m ? nz : m; bool above= pen && strchr(pen,'a'); bool wire = pen && strchr(pen,'#'); - float *dd=new float[2*n], x1,z0,zz,d; - memset(dd,0,n*sizeof(float)); + mreal *dd=new mreal[2*n], x1,z0,zz,d, vx,vy,vz,v0,v1; gr->SetPenPal(pen,&pal); char c1[7]; memset(c1,0,7); c1[0] ='@'; char c2[7]; memset(c2,0,7); c2[0] ='@'; if(wire) c1[5]=c2[5]='#'; - memset(dd,0,2*n*sizeof(float)); + memset(dd,0,2*n*sizeof(mreal)); z0 = gr->GetOrgZ('x'); - for(i=0;iv(i, jGetNy() ? j:0); + for(i=0;iv(i, jNextColor(pal); memcpy(c1+1,gr->last_line(),4); if(gr->GetNumPal(pal)==2*m) { gr->NextColor(pal); memcpy(c2+1,gr->last_line(),4); } else memcpy(c2,c1,7); - mx = jGetNy() ? j:0; my = jGetNy() ? j:0; mz = jGetNy() ? j:0; + mx = jGetNy() ? j:0; my = jGetNy() ? j:0; mz = jStop) { delete []dd; return; } - d = iv(i+1,mx)-x->v(i,mx) : x->v(i,mx)-x->v(i-1,mx); - x1 = (nv(i,mx)+x->v(i+1,mx))/2:x->v(i,mx)) + d/2*(1-0.7*gr->BarWidth); + vx=x->v(i,mx); vy=y->v(i,my); vz=z->v(i,mz); + v0=y->v(i,0); v1=iv(i+1,mx):x->v(i-1,mx); + d = iBarWidth); if(above) { - zz = j>0?dd[i+n]:z0; dd[i+n] += z->v(i,mz); - mgl_cone(gr, x1,y->v(i,0),zz, x1,y->v(i,0),dd[i+n], + zz = j>0?dd[i+n]:z0; dd[i+n] += vz; + mgl_cone(gr, x1,v0,zz, x1,v0,dd[i+n], 0.7*gr->BarWidth*d*(dd[i]-zz)/(dd[i]-z0), 0.7*gr->BarWidth*d*(dd[i]-dd[i+n])/(dd[i]-z0), c1); } - else mgl_cone(gr, x1,y->v(i,my),z0, x1,y->v(i,my),z->v(i,mz), 0.7*gr->BarWidth*d,0, z->v(i,mz)<0?c1:c2); + else mgl_cone(gr, x1,vy,z0, x1,vy,vz, 0.7*gr->BarWidth*d,0, vz<0?c1:c2); } } gr->EndGroup(); delete []dd; @@ -310,15 +307,16 @@ void mgl_cones_xz(HMGL gr, HCDT x, HCDT z, const char *pen, const char *opt) mglData y(z); y.Fill(gr->Min.y,gr->Max.y,'y'); mgl_cones_xyz(gr,x,&y,z,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_cones(HMGL gr, HCDT z, const char *pen, const char *opt) { - if(z->GetNx()<2) { gr->SetWarn(mglWarnLow,"Bars"); return; } gr->SaveState(opt); mglData x(z->GetNx()+1); x.Fill(gr->Min.x,gr->Max.x); mgl_cones_xz(gr,&x,z,pen,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_cones_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, const char *pen, const char *opt,int l,int lo) @@ -340,13 +338,14 @@ void mgl_cones_(uintptr_t *gr, uintptr_t *y, const char *pen, const char *opt,in // Ellipse & Rhomb // //----------------------------------------------------------------------------- -void mgl_ellipse(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, float r, const char *stl) +void mgl_ellipse(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal r, const char *stl) { const int n = 41; long pal=0,n0,n1=-1,n2,m1=-1,m2; + static int cgid=1; gr->StartGroup("Ellipse",cgid++); gr->SetPenPal(stl,&pal); - float c=gr->NextColor(pal), d; - float k=(gr->GetNumPal(pal)>1)?gr->NextColor(pal):gr->AddTexture('k'); + mreal c=gr->NextColor(pal), d; + mreal k=(gr->GetNumPal(pal)>1)?gr->NextColor(pal):gr->AddTexture('k'); bool fill = !(stl && strchr(stl,'#')), box = (stl && strchr(stl,'@')) || !fill; if(!fill) k=c; @@ -361,7 +360,7 @@ void mgl_ellipse(HMGL gr, float x1, float y1, float z1, float x2, float y2, floa for(long i=0;iStop) return; - float t = i*2*M_PI/(n-1.); + mreal t = i*2*M_PI/(n-1.); p = s+v*cos(t)+u*sin(t); n2 = n1; n1 = gr->AddPnt(p,c,q,-1,11); m2 = m1; m1 = gr->CopyNtoC(n1,k); @@ -371,15 +370,17 @@ void mgl_ellipse(HMGL gr, float x1, float y1, float z1, float x2, float y2, floa if(box) gr->line_plot(m1,m2); } } + gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_rhomb(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, float r, const char *stl) +void mgl_rhomb(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal r, const char *stl) { long pal=0, n1,n2,n3,n4; + static int cgid=1; gr->StartGroup("Rhomb",cgid++); gr->SetPenPal(stl,&pal); - float c=gr->NextColor(pal); - float k=(gr->GetNumPal(pal)>1)?gr->NextColor(pal):gr->AddTexture('k'); - float b=(gr->GetNumPal(pal)>2)?gr->NextColor(pal):c; + mreal c=gr->NextColor(pal); + mreal k=(gr->GetNumPal(pal)>1)?gr->NextColor(pal):gr->AddTexture('k'); + mreal b=(gr->GetNumPal(pal)>2)?gr->NextColor(pal):c; bool fill = !(stl && strchr(stl,'#')), box = (stl && strchr(stl,'@')) || !fill; if(!fill) k=c; gr->Reserve(8); @@ -395,13 +396,14 @@ void mgl_rhomb(HMGL gr, float x1, float y1, float z1, float x2, float y2, float if(box) { gr->line_plot(n1,n2); gr->line_plot(n2,n3); gr->line_plot(n3,n4); gr->line_plot(n4,n1); } + gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_ellipse_(uintptr_t* gr, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, float *r, const char *stl,int l) +void mgl_ellipse_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, mreal *r, const char *stl,int l) { char *s=new char[l+1]; memcpy(s,stl,l); s[l]=0; mgl_ellipse(_GR_,*x1,*y1,*z1,*x2,*y2,*z2,*r,s); delete []s; } //----------------------------------------------------------------------------- -void mgl_rhomb_(uintptr_t* gr, float *x1, float *y1, float *z1, float *x2, float *y2, float *z2, float *r, const char *stl,int l) +void mgl_rhomb_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal *y2, mreal *z2, mreal *r, const char *stl,int l) { char *s=new char[l+1]; memcpy(s,stl,l); s[l]=0; mgl_rhomb(_GR_,*x1,*y1,*z1,*x2,*y2,*z2,*r,s); delete []s; } //----------------------------------------------------------------------------- @@ -409,14 +411,14 @@ void mgl_rhomb_(uintptr_t* gr, float *x1, float *y1, float *z1, float *x2, float // Sphere & Drop // //----------------------------------------------------------------------------- -void mgl_sphere(HMGL gr, float x, float y, float z, float r, const char *stl) +void mgl_sphere(HMGL gr, mreal x, mreal y, mreal z, mreal r, const char *stl) { mgl_drop(gr,x,y,z,1,0,0,2*r,stl,0,1); } //----------------------------------------------------------------------------- void mgl_sphere_(uintptr_t* gr, mreal *x, mreal *y, mreal *z, mreal *r, const char *stl,int l) { char *s=new char[l+1]; memcpy(s,stl,l); s[l]=0; mgl_sphere(_GR_, *x,*y,*z,*r,s); delete []s; } //----------------------------------------------------------------------------- -void mgl_drop(HMGL gr, mglPoint p, mglPoint q, float r, float c, float sh, float a) +void mgl_drop(HMGL gr, mglPoint p, mglPoint q, mreal r, mreal c, mreal sh, mreal a) { mglPoint p1,p2,pp,qq; if(q.norm()==0) { q = mglPoint(1,0,0); sh=0; } @@ -428,7 +430,7 @@ void mgl_drop(HMGL gr, mglPoint p, mglPoint q, float r, float c, float sh, float gr->Reserve(n*n); long *nn=new long[2*n]; - float u,v,x,y,z,rr,dr, co,si; + mreal u,v,x,y,z,rr,dr, co,si; for(i=0;iStop) { delete []nn; return; } @@ -446,9 +448,9 @@ void mgl_drop(HMGL gr, mglPoint p, mglPoint q, float r, float c, float sh, float delete []nn; gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_drop(HMGL gr, float x1, float y1, float z1, float x2, float y2, float z2, float r, const char *stl, float sh, float a) +void mgl_drop(HMGL gr, mreal x1, mreal y1, mreal z1, mreal x2, mreal y2, mreal z2, mreal r, const char *stl, mreal sh, mreal a) { - float c=gr->AddTexture((stl && stl[0]) ? stl[0]:'r'); + mreal c=gr->AddTexture((stl && stl[0]) ? stl[0]:'r'); mgl_drop(gr,mglPoint(x1,y1,z1), mglPoint(x2,y2,z2), r, c, sh, a); } //----------------------------------------------------------------------------- @@ -463,17 +465,15 @@ void mgl_drop_(uintptr_t* gr, mreal *x1, mreal *y1, mreal *z1, mreal *x2, mreal void mgl_dew_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt) { long i,j,n=ax->GetNx(),m=ax->GetNy(),k; - if(n*m*ax->GetNz()!=ay->GetNx()*ay->GetNy()*ay->GetNz()) { gr->SetWarn(mglWarnDim,"Dew"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Dew"); return; } - bool both = x->GetNx()==n && y->GetNx()==n && x->GetNy()==m && y->GetNy()==m; - if(!(both || (x->GetNx()==n && y->GetNx()==m))) { gr->SetWarn(mglWarnDim,"Dew"); return; } + if(mgl_check_dim2(gr,x,y,ax,ay,"Dew")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("DewXY",cgid++); - float xm,ym,dx,dy,dd; + mreal xm,ym,dx,dy,dd; long ss = gr->AddTexture(sch); bool inv = sch && strchr(sch,'A'); - float zVal = gr->Min.z; + mreal zVal = gr->Min.z; long tx=1,ty=1; if(gr->MeshNum>1) { tx=(n-1)/(gr->MeshNum-1); ty=(m-1)/(gr->MeshNum-1); } if(tx<1) tx=1; if(ty<1) ty=1; @@ -483,30 +483,24 @@ void mgl_dew_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, cons ym = sqrt(ax->v(i,j,k)*ax->v(i,j,k)+ay->v(i,j,k)*ay->v(i,j,k)); xm = xm>ym ? xm : ym; } -/* for(i=0,xm=0;iGetNz();i++) - { - ym = hypot(ax->vthr(i),ay->vthr(i)); - xm = xm>ym ? xm : ym; - }*/ - xm = 1./MGL_FLT_EPS/(xm==0 ? 1:xm); - mglPoint p,q; + xm = 1./MGL_EPSILON/(xm==0 ? 1:xm); + mglPoint q; for(k=0;kGetNz();k++) { - if(ax->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*float(k)/(ax->GetNz()-1); + if(ax->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(k)/(ax->GetNz()-1); for(i=0;iStop) return; - float xx=GetX(x,i,j,k).x, yy=GetY(y,i,j,k).x; + mreal xx=GetX(x,i,j,k).x, yy=GetY(y,i,j,k).x; dx = iv(i,j,k),-ay->v(i,j,k),0) : mglPoint(ax->v(i,j,k),ay->v(i,j,k),0); - p = mglPoint(xx, yy, zVal); dd = q.norm(); - float ccc = gr->GetC(ss,dd*xm,false); - mgl_drop(gr,p,q,(dxv(i,j,k),ay->v(i,j,k)); dd = q.norm(); + if(inv) q = -q; + mreal ccc = gr->GetC(ss,dd*xm,false); + mgl_drop(gr,mglPoint(xx, yy, zVal),q,(dxEndGroup(); @@ -514,12 +508,12 @@ void mgl_dew_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, cons //----------------------------------------------------------------------------- void mgl_dew_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, const char *opt) { - if(ax->GetNx()<2 || ax->GetNy()<2) { gr->SetWarn(mglWarnLow,"Vect"); return; } gr->SaveState(opt); mglData x(ax->GetNx()), y(ax->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_dew_xy(gr,&x,&y,ax,ay,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_dew_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int l,int lo) @@ -536,12 +530,12 @@ void mgl_dew_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, c // Puts series // //----------------------------------------------------------------------------- -void mgl_puts(HMGL gr, float x, float y, float z,const char *text, const char *font, float size) +void mgl_puts(HMGL gr, mreal x, mreal y, mreal z,const char *text, const char *font, mreal size) { mgl_puts_dir(gr, x, y, z, NAN, NAN, 0, text, font, size); } -void mgl_putsw(HMGL gr, float x, float y, float z,const wchar_t *text, const char *font, float size) +void mgl_putsw(HMGL gr, mreal x, mreal y, mreal z,const wchar_t *text, const char *font, mreal size) { mgl_putsw_dir(gr, x, y, z, NAN, NAN, 0, text, font, size); } //----------------------------------------------------------------------------- -void mgl_puts_dir(HMGL gr, float x, float y, float z, float dx, float dy, float dz, const char *text, const char *font, float size) +void mgl_puts_dir(HMGL gr, mreal x, mreal y, mreal z, mreal dx, mreal dy, mreal dz, const char *text, const char *font, mreal size) { long len = strlen(text); wchar_t *buf = new wchar_t[len+1]; @@ -550,7 +544,7 @@ void mgl_puts_dir(HMGL gr, float x, float y, float z, float dx, float dy, float delete []buf; } //----------------------------------------------------------------------------- -void mgl_putsw_dir(HMGL gr, float x, float y, float z, float dx, float dy, float dz, const wchar_t *text, const char *font, float size) +void mgl_putsw_dir(HMGL gr, mreal x, mreal y, mreal z, mreal dx, mreal dy, mreal dz, const wchar_t *text, const char *font, mreal size) { bool a=font && strchr(font,'a'), A=font && strchr(font,'A'); mglCanvas *g = dynamic_cast(gr); @@ -558,7 +552,7 @@ void mgl_putsw_dir(HMGL gr, float x, float y, float z, float dx, float dy, float { g->Push(); g->Identity(a); gr->set(MGL_DISABLE_SCALE); - register float s=a?1:g->GetPlotFactor(); + register mreal s=a?1:g->GetPlotFactor(); x = (2*x-1)*s; y = (2*y-1)*s; dx= (2*dx-1)*s; dy= (2*dy-1)*s; } @@ -568,13 +562,13 @@ void mgl_putsw_dir(HMGL gr, float x, float y, float z, float dx, float dy, float gr->text_plot(k,text,font,size); } //----------------------------------------------------------------------------- -void mgl_puts_(uintptr_t *gr, float *x, float *y, float *z,const char *text, const char *font, float *size, int l, int n) +void mgl_puts_(uintptr_t *gr, mreal *x, mreal *y, mreal *z,const char *text, const char *font, mreal *size, int l, int n) { wchar_t *s=new wchar_t[l+1]; mbstowcs(s,text,l); s[l]=0; char *f=new char[n+1]; memcpy(f,font,n); f[n]=0; mgl_putsw_dir(_GR_, *x, *y, *z, NAN, NAN, 0, s, f, *size); delete []s; delete []f; } //----------------------------------------------------------------------------- -void mgl_puts_dir_(uintptr_t *gr, float *x, float *y, float *z, float *dx, float *dy, float *dz, const char *text, const char *font, float *size, int l, int n) +void mgl_puts_dir_(uintptr_t *gr, mreal *x, mreal *y, mreal *z, mreal *dx, mreal *dy, mreal *dz, const char *text, const char *font, mreal *size, int l, int n) { wchar_t *s=new wchar_t[l+1]; mbstowcs(s,text,l); s[l]=0; char *f=new char[n+1]; memcpy(f,font,n); f[n]=0; mgl_putsw_dir(_GR_, *x, *y, *z, *dx, *dy, *dz, s, f, *size); @@ -587,9 +581,8 @@ void mgl_puts_dir_(uintptr_t *gr, float *x, float *y, float *z, float *dx, float void mgl_textmarkw_xyzr(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT r, const wchar_t *text, const char *fnt, const char *opt) { long j,m,mx,my,mz,mr,n=y->GetNx(); - if(x->GetNx()!=n || z->GetNx()!=n || r->GetNx()!=n) - { gr->SetWarn(mglWarnDim,"TextMark"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"TextMark"); return; } + if(mgl_check_dim1(gr,x,y,z,r,"TextMark")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("TextMark",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); @@ -619,25 +612,30 @@ void mgl_textmarkw_xyr(HMGL gr, HCDT x, HCDT y, HCDT r, const wchar_t *text, con gr->SaveState(opt); mglData z(y->GetNx()); z.Fill(gr->Min.z,gr->Min.z); mgl_textmarkw_xyzr(gr,x,y,&z,r,text,fnt,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_textmarkw_yr(HMGL gr, HCDT y, HCDT r, const wchar_t *text, const char *fnt, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"TextMark"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"TextMark"); return; } gr->SaveState(opt); - mglData x(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); - mglData z(y->GetNx()); z.Fill(gr->Min.z,gr->Min.z); + mglData x(n); x.Fill(gr->Min.x,gr->Max.x); + mglData z(n); z.Fill(gr->Min.z,gr->Min.z); mgl_textmarkw_xyzr(gr,&x,y,&z,r,text,fnt,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_textmarkw(HMGL gr, HCDT y, const wchar_t *text, const char *fnt, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"TextMark"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"TextMark"); return; } gr->SaveState(opt); - mglData r(y->GetNx()); r.Fill(1,1); - mglData x(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); - mglData z(y->GetNx()); z.Fill(gr->Min.z,gr->Min.z); + mglData r(n); r.Fill(1,1); + mglData x(n); x.Fill(gr->Min.x,gr->Max.x); + mglData z(n); z.Fill(gr->Min.z,gr->Min.z); mgl_textmarkw_xyzr(gr,&x,y,&z,&r,text,fnt,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_textmark_xyzr(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT r, const char *str, const char *fnt, const char *opt) @@ -683,38 +681,15 @@ void mgl_textmark_(uintptr_t *gr, uintptr_t *y, const char *text, const char *fn mgl_textmarkw(_GR_, _DA_(y),s,f, o); delete []o; delete []s; delete []f; } //----------------------------------------------------------------------------- // -// PutsFit series -// -//----------------------------------------------------------------------------- -extern char mglFitRes[1024]; ///< Last fitted formula -void mgl_puts_fit(HMGL gr, float x, float y, float z, const char *pre, const char *font, float size) -{ - long n = strlen(mglFitRes)+(pre?strlen(pre):0)+1; - char *buf = new char[n]; - if(pre) sprintf(buf,"%s%s",pre,mglFitRes); - else strcpy(buf,mglFitRes); - mgl_puts(gr,x,y,z,buf,font,size); - delete []buf; -} -void mgl_puts_fit_(uintptr_t* gr, mreal *x, mreal *y, mreal *z, const char *prefix, const char *font, mreal *size, int l, int n) -{ - char *s=new char[l+1]; memcpy(s,prefix,l); s[l]=0; - char *d=new char[n+1]; memcpy(d,font,n); d[n]=0; - mgl_puts_fit(_GR_, *x,*y,*z, s, d, *size); - delete []s; delete []d; -} -//----------------------------------------------------------------------------- -// -// TextMark series +// Label series // //----------------------------------------------------------------------------- void mgl_labelw_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const wchar_t *text, const char *fnt, const char *opt) { long j,m,mx,my,mz,n=y->GetNx(); - if(x->GetNx()!=n || z->GetNx()!=n) - { gr->SetWarn(mglWarnDim,"Label"); return; } - if(n<2) { gr->SetWarn(mglWarnLow,"Label"); return; } - float size=gr->SaveState(opt); if(mgl_isnan(size)) size=-0.7; + if(mgl_check_dim1(gr,x,y,z,0,"Label")) return; + + mreal size=gr->SaveState(opt); if(mgl_isnan(size)) size=-0.7; static int cgid=1; gr->StartGroup("Label",cgid++); m = x->GetNy() > y->GetNy() ? x->GetNy() : y->GetNy(); m = z->GetNy() > m ? z->GetNy() : m; @@ -730,7 +705,7 @@ void mgl_labelw_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const wchar_t *text, const for(i=0;iStop) { delete []buf; return; } - float xx=x->v(i,mx), yy=y->v(i,my), zz=z->v(i,mz); + mreal xx=x->v(i,mx), yy=y->v(i,my), zz=z->v(i,mz); p = mglPoint(xx,yy,zz); kk = gr->AddPnt(p,-1,q); memset(buf,0,nn*sizeof(wchar_t)); @@ -744,7 +719,7 @@ void mgl_labelw_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const wchar_t *text, const else if(text[k+1]=='z') mglprintf(buf+l,nn-l,L"%.2g",zz); l=wcslen(buf); k++; } - gr->text_plot(kk, buf, fnt, size, 0.03); + gr->text_plot(kk, buf, fnt, size, 0.05); } } delete []buf; gr->EndGroup(); @@ -755,15 +730,18 @@ void mgl_labelw_xy(HMGL gr, HCDT x, HCDT y, const wchar_t *text, const char *fnt gr->SaveState(opt); mglData z(y->GetNx()); z.Fill(gr->Min.z,gr->Min.z); mgl_labelw_xyz(gr,x,y,&z,text,fnt,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_labelw_y(HMGL gr, HCDT y, const wchar_t *text, const char *fnt, const char *opt) { - if(y->GetNx()<2) { gr->SetWarn(mglWarnLow,"TextMark"); return; } + register long n=y->GetNx(); + if(n<2) { gr->SetWarn(mglWarnLow,"TextMark"); return; } gr->SaveState(opt); - mglData x(y->GetNx()); x.Fill(gr->Min.x,gr->Max.x); - mglData z(y->GetNx()); z.Fill(gr->Min.z,gr->Min.z); + mglData x(n); x.Fill(gr->Min.x,gr->Max.x); + mglData z(n); z.Fill(gr->Min.z,gr->Min.z); mgl_labelw_xyz(gr,&x,y,&z,text,fnt,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_label_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, const char *str, const char *fnt, const char *opt) diff --git a/src/s_hull/COPYING.txt b/src/s_hull/COPYING.txt index 77b475d..e11e9cf 100644 --- a/src/s_hull/COPYING.txt +++ b/src/s_hull/COPYING.txt @@ -41,3 +41,9 @@ copying the code. or you could email david@s-hull.org and arrange to make a donation of 10 of your local currancy units to support s-hull.org. +------------------- + +This is permission to use s-hull-pro mathgl as long as the routines retain +my copyright notice. I an happy for it to be included in an LGPL product and +I am happy for the source to be bundled with mathgl under whatever license you +use for that. diff --git a/src/s_hull/s_hull.C b/src/s_hull/s_hull.C deleted file mode 100755 index 5fb1c1f..0000000 --- a/src/s_hull/s_hull.C +++ /dev/null @@ -1,1598 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - - -#include "s_hull.h" - -/* - fast and simple convex hull finder. - kind of a circular vesion of Steven Fortune's sweepline algorithm -but without the complicated bits. - - and combined with link insertion and flipping will give you Delaunay triangles.. - -S-hull, Copyright (c) 2010 -Dr David SInclair -Cambridge, UK - -email david@s-hull.org -S-hull is free software and may be obtained from www.s-hull.org. -It may be freely copied, modified, -and redistributed under the following conditions which might loosely be termed a contribtors beerware license: -1. All copyright notices must remain intact in all files. -2. A copy of this text file must be distributed along with any copies - of S-hull that you redistribute; this includes copies that you have - modified, or copies of programs or other software products that - include S-hull where distributed as source. - -3. If you modify S-hull, you must include a notice giving the - name of the person performing the modification, the date of - modification, and the reason for such modification. - -4. If you are distributing a binary or compiled version of s-hull it - is not necessary to include any acknowledgement or reference - to s-hull. -5. There is no warranty or other guarantee of fitness for S-hull, it is - provided solely "as is". Bug reports or fixes may be sent to - bugs@s-hull.org; the authors may or may not act on them as - they desire. -6. By copying or compliing the code for S-hull you explicitly indemnify -the copyright holder against any liability he may incur as a result of you -copying the code. - -7. If you meet any of the contributors to the code you used from s-hull.org - in a pub or a bar, and you think the source code they contributed to is worth it, - you can buy them a beer. - - If your principles run against beer a bacon-double-cheeseburger would do just as nicely - or you could email david@s-hull.org and arrange to make a donation of 10 of your local currancy units - to support s-hull.org. - - - */ - - - - - -void circle_cent2(float r1,float c1, float r2,float c2, float r3,float c3, -float &r,float &c, float &ro2){ - /* - * function to return the center of a circle and its radius - * degenerate case should never be passed to this routine!!!!!!!!!!!!! - * but will return r0 = -1 if it is. - */ - - float v1 = 2*(r2-r1), v2 = 2*(c2-c1), v3 = r2*r2 - r1*r1 + c2*c2 - c1*c1; - float v4 = 2*(r3-r1), - v5 = 2*(c3-c1), - v6 = r3*r3 - r1*r1 + c3*c3 - c1*c1, - - v7 = v2*v4 - v1*v5; - if( v7 == 0 ){ - r=0; - c=0; - ro2 = -1; - return; - } - - c = (v4*v3 - v1*v6)/v7; - if( v1 != 0 ) - r = (v3 - c*v2)/v1; - else - r = (v6 - c*v5)/v4; - - ro2 = ( (r-r1)*(r-r1) + (c-c1)*(c-c1) ); - - return; -} - - -void write_Shx(std::vector &pts, char * fname){ - std::ofstream out(fname, ios::out); - - int nr = pts.size(); - out << nr << " 2" << endl; - - for (int r = 0; r < nr; r++){ - out << pts[r].r << ' ' << pts[r].c << endl; - } - out.close(); - - return; -}; - - - -/* - write out triangle ids to be compatible with matlab/octave array numbering. - - */ -void write_Triads(std::vector &ts, char * fname){ - std::ofstream out(fname, ios::out); - - int nr = ts.size(); - out << nr << " 7" << endl; - - for (int r = 0; r < nr; r++){ - out << ts[r].a+1 << ' ' << ts[r].b+1 <<' ' << ts[r].c+1 <<' ' - << ts[r].ab+1 <<' ' << ts[r].ac+1 <<' ' << ts[r].bc+1 << " " << ts[r].ro << endl; - } - out.close(); - - return; -}; - - - - -void T_flip2( std::vector &pts, std::vector &triads, int *slump, int numt, int start){ - - float R,C,r0,c0, r1,c1, r2,c2, r3,c3, rot, rot2, dR, dC; - int pa,pb,pc, pd, ab, bc, ac, D, L1, L2, L3, L4, T2; - std::vector aliens; - Triad tx, tx2; - std::set ids; - - for( int t=start; t= 0 ){ - T2 = tri.bc; - Triad &t2 = triads[T2]; - // find relative orientation (shared limb). - if( t2.ab == t ){ - D = t2.c; - pd = slump[t2.c]; - - if( tri.a == t2.a){ - L3 = t2.ac; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ac; - } - } - else if( t2.ac == t ){ - D = t2.b; - pd = slump[t2.b]; - - if( tri.a == t2.a){ - L3 = t2.ab; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ab; - } - } - else if( t2.bc == t ){ - D = t2.a; - pd = slump[t2.a]; - - if( tri.b == t2.b){ - L3 = t2.ab; - L4 = t2.ac; - } - else{ - L3 = t2.ac; - L4 = t2.ab; - } - } - else{ - cerr << "fuck up at line 12 dude!" << endl; - } - - r3 = pts[pd].r; - c3 = pts[pd].c; - dR = tri.R-r3; - dC = tri.C-c3; - - - if( dR*dR+dC*dC < tri.ro ){ // not valid in the Delaunay sense. - L1 = tri.ab; - L2 = tri.ac; - - circle_cent2(pts[pa].r, pts[pa].c, pts[pb].r, pts[pb].c, r3, c3, R, C , rot); - - tx.a = tri.a; - tx.b = tri.b; - tx.c = D; - tx.ro = rot; - tx.R = R; - tx.C = C; - - tx.ab = L1; - tx.ac = T2; - tx.bc = L3; - - - // triangle 2; - tx2.a = tri.a; - tx2.b = tri.c; - tx2.c = D; - circle_cent2(pts[pa].r, pts[pa].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - tx2.ro = rot; - tx2.R = R; - tx2.C = C; - - tx2.ab = L2; - tx2.ac = t; - tx2.bc = L4; - - - ids.insert(t); - ids.insert(T2); - - t2 = tx2; - tri = tx; - flipped = 1; - - // change knock on triangle labels. - if( L3 >= 0 ){ - Triad &t3 = triads[L3]; - if( t3.ab == T2 ) t3.ab = t; - else if( t3.bc == T2 ) t3.bc = t; - else if( t3.ac == T2 ) t3.ac = t; - } - - if(L2 >= 0 ){ - Triad &t4 = triads[L2]; - if( t4.ab == t ) t4.ab = T2; - else if( t4.bc == t ) t4.bc = T2; - else if( t4.ac == t ) t4.ac = T2; - } - - } - } - - //write_Triads(triads, "tflip1.mat"); - int df = 9; - df = 8; - } - - - - - - - return; -} - - - -/* version in which the ids of the triangles associated with the sides of the hull are tracked. - - - */ - -void s_hull_del_ray2( std::vector &pts, std::vector &triads) -{ - - int nump = pts.size(); - - - float r = pts[0].r; - float c = pts[0].c; - for( int k=0; k 0 ){ - mid = k; - romin2 = ro2; - R = r; - C = c; - - } - else if( romin2 *4 < pts[k].ro ) - k=nump; - - k++; - } - - //std::cerr << "earwig noodles " << pts[1].id << " " << pts[mid].id << " " << romin2 << endl; - - Shx pt0 = pts[0]; - Shx pt1 = pts[1]; - Shx pt2 = pts[mid]; - - pts.erase(pts.begin() + mid); // necessary for round off reasons:(((((( - pts.erase(pts.begin() ); - pts.erase(pts.begin() ); - - for( int k=0; k hull; - - - r = (pts[0].r + pts[1].r + pts[2].r )/3.0; - c = (pts[0].c + pts[1].c + pts[2].c )/3.0; - - float dr0 = pts[0].r - r, dc0 = pts[0].c - c; - float tr01 = pts[1].r - pts[0].r, tc01 = pts[1].c - pts[0].c; - - float df = -tr01* dc0 + tc01*dr0; - if( df < 0 ){ // [ 0 1 2 ] - pt0.tr = pt1.r-pt0.r; - pt0.tc = pt1.c-pt0.c; - pt0.trid = 0; - hull.push_back( pt0 ); - - pt1.tr = pt2.r-pt1.r; - pt1.tc = pt2.c-pt1.c; - pt1.trid = 0; - hull.push_back( pt1 ); - - pt2.tr = pt0.r-pt2.r; - pt2.tc = pt0.c-pt2.c; - pt2.trid = 0; - hull.push_back( pt2 ); - - - Triad tri(pt0.id,pt1.id,pt2.id); - tri.ro = romin2; - tri.R = R; - tri.C = C; - - triads.push_back(tri); - - } - else{ // [ 0 2 1 ] as anti-clockwise turning is the work of the devil.... - pt0.tr = pt2.r-pt0.r; - pt0.tc = pt2.c-pt0.c; - pt0.trid = 0; - hull.push_back( pt0 ); - - pt2.tr = pt1.r-pt2.r; - pt2.tc = pt1.c-pt2.c; - pt2.trid = 0; - hull.push_back( pt2 ); - - pt1.tr = pt0.r-pt1.r; - pt1.tc = pt0.c-pt1.c; - pt1.trid = 0; - hull.push_back( pt1 ); - - Triad tri(pt0.id,pt2.id,pt1.id); - tri.ro = romin2; - tri.R = R; - tri.C = C; - triads.push_back(tri); - } - - // add new points into hull (removing obscured ones from the chain) - // and creating triangles.... - // that will need to be flipped. - - float dr, dc, rx,cx; - Shx ptx; - int numt; - - for( int k=3; k pidx, tridx; - int hidx; // new hull point location within hull..... - - - float df = -dc* hull[0].tr + dr*hull[0].tc; // visibility test vector. - if( df < 0 ){ // starting with a visible hull facet !!! - int e1 = 1, e2 = numh; - hidx = 0; - - // check to see if segment numh is also visible - df = -dc* hull[numh-1].tr + dr*hull[numh-1].tc; - //cerr << df << ' ' ; - if( df < 0 ){ // visible. - pidx.push_back(hull[numh-1].id); - tridx.push_back(hull[numh-1].trid); - - - for( int h=0; h0; h--){ - // if segment h is visible delete h + 1 - dr = rx- hull[h].r; dc = cx- hull[h].c; - df = -dc* hull[h].tr + dr*hull[h].tc; - - if( df < 0 ){ // h is visible - pidx.insert(pidx.begin(), hull[h].id); - tridx.insert(tridx.begin(), hull[h].trid); - hull.erase(hull.begin() + h+1); // erase end of chain - - } - else{ - - h = hull.size()-1; - hull[h].tr = -hull[h].r + ptx.r; // points at start of chain. - hull[h].tc = -hull[h].c + ptx.c; - break; - } - } - - df = 9; - - } - else{ - // cerr << df << ' ' << endl; - hidx = 1; // keep pt hull[0] - tridx.push_back(hull[0].trid); - pidx.push_back(hull[0].id); - - for( int h=1; h 0 ){ // first invisible segment. - e2 = h; - break; - } - } - - } - - - // triangle pidx starts at e1 and ends at e2 (inclusive). - if( e2 < numh ){ - for( int e=e1; e<=e2; e++){ - pidx.push_back(hull[e].id); - tridx.push_back(hull[e].trid); - } - } - else{ - for( int e=e1; e 0 ) - hull[hidx-1].trid = numt; - else{ - numh = hull.size(); - hull[numh-1].trid = numt; - } - triads.push_back( trx ); - numt++; - } - - else{ - trx.ab = -1; - for(int p=0; p 0 ) - trx.ab = numt-1; - trx.ac = numt+1; - - // index back into the triads. - Triad &txx = triads[tridx[p]]; - if( ( trx.b == txx.a && trx.c == txx.b) |( trx.b == txx.b && trx.c == txx.a)) { - txx.ab = numt; - } - else if( ( trx.b == txx.a && trx.c == txx.c) |( trx.b == txx.c && trx.c == txx.a)) { - txx.ac = numt; - } - else if( ( trx.b == txx.b && trx.c == txx.c) |( trx.b == txx.c && trx.c == txx.b)) { - txx.bc = numt; - } - - if( trx.ab == 26777 || trx.ac == 26777 || trx.bc == 26777){ - int foon = 7; - } - - triads.push_back( trx ); - numt++; - } - triads[numt-1].ac=-1; - - hull[hidx].trid = numt-1; - if( hidx > 0 ) - hull[hidx-1].trid = T0; - else{ - numh = hull.size(); - hull[numh-1].trid = T0; - } - - - } - - - // write_Triads(triads, "tris.mat"); - //int dfx = 9; - //T_flip2( pts, triads, slump, numt, T0); - - //write_Triads(triads, "tris2.mat"); - - } - - cerr << "of triangles " << triads.size() << " to be flipped. "<< endl; - - //write_Triads(triads, "tris0.mat"); - - std::set ids, ids2; - T_flip3( pts, triads, slump, numt, 0, ids); - - - int nits = ids.size(), nit=1; - while( nits > 0 && nit < 20){ - // char nam[128]; - //sprintf(nam, "tris_%d.mat", nit); - //write_Triads(triads, nam); - - T_flip4( pts, triads, slump, ids); - nits = ids.size(); - nit ++; - - } - //write_Triads(triads, "triangles3.mat"); - - return; -} - -/* - flip pairs of triangles that are not valid delaunay triangles - (the test used is the circum circle not containing any point of the other triangle (in bad English)) - - */ - - -void T_flip3( std::vector &pts, std::vector &triads, int *slump, int numt, int start, std::set &ids){ - - float R,C,r0,c0, r1,c1, r2,c2, r3,c3, rot, rot2, dR, dC; - int pa,pb,pc, pd, ab, bc, ac, D, L1, L2, L3, L4, T2; - std::vector aliens; - Triad tx, tx2; - //std::set ids; - - for( int t=start; t= 0 ){ - - pa = slump[tri.a]; - pb = slump[tri.b]; - pc = slump[tri.c]; - - T2 = tri.bc; - Triad &t2 = triads[T2]; - // find relative orientation (shared limb). - if( t2.ab == t ){ - D = t2.c; - pd = slump[t2.c]; - - if( tri.b == t2.a){ - L3 = t2.ac; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ac; - } - } - else if( t2.ac == t ){ - D = t2.b; - pd = slump[t2.b]; - - if( tri.b == t2.a){ - L3 = t2.ab; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ab; - } - } - else if( t2.bc == t ){ - D = t2.a; - pd = slump[t2.a]; - - if( tri.b == t2.b){ - L3 = t2.ab; - L4 = t2.ac; - } - else{ - L3 = t2.ac; - L4 = t2.ab; - } - } - else{ - cerr << "fuck up at line 12 dude! " << t << endl; - } - - r3 = pts[pd].r; - c3 = pts[pd].c; - dR = tri.R-r3; - dC = tri.C-c3; - - - if( dR*dR+dC*dC < tri.ro ){ // not valid in the Delaunay sense. - L1 = tri.ab; - L2 = tri.ac; - if( L1 != L3 && L2 != L4 ){ // need this check for stability. - - circle_cent2(pts[pa].r, pts[pa].c, pts[pb].r, pts[pb].c, r3, c3, R, C , rot); - - tx.a = tri.a; - tx.b = tri.b; - tx.c = D; - tx.ro = rot; - tx.R = R; - tx.C = C; - - tx.ab = L1; - tx.ac = T2; - tx.bc = L3; - - - // triangle 2; - tx2.a = tri.a; - tx2.b = tri.c; - tx2.c = D; - circle_cent2(pts[pa].r, pts[pa].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - tx2.ro = rot; - tx2.R = R; - tx2.C = C; - - tx2.ab = L2; - tx2.ac = t; - tx2.bc = L4; - - - ids.insert(t); - ids.insert(T2); - - t2 = tx2; - tri = tx; - flipped = 1; - - // change knock on triangle labels. - if( L3 >= 0 ){ - Triad &t3 = triads[L3]; - if( t3.ab == T2 ) t3.ab = t; - else if( t3.bc == T2 ) t3.bc = t; - else if( t3.ac == T2 ) t3.ac = t; - } - - if(L2 >= 0 ){ - Triad &t4 = triads[L2]; - if( t4.ab == t ) t4.ab = T2; - else if( t4.bc == t ) t4.bc = T2; - else if( t4.ac == t ) t4.ac = T2; - } - } - } - } - - - if( flipped == 0 && tri.ab >= 0 ){ - - pc = slump[tri.c]; - pb = slump[tri.b]; - pa = slump[tri.a]; - - T2 = tri.ab; - Triad &t2 = triads[T2]; - // find relative orientation (shared limb). - if( t2.ab == t ){ - D = t2.c; - pd = slump[t2.c]; - - if( tri.a == t2.a){ - L3 = t2.ac; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ac; - } - } - else if( t2.ac == t ){ - D = t2.b; - pd = slump[t2.b]; - - if( tri.a == t2.a){ - L3 = t2.ab; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ab; - } - } - else if( t2.bc == t ){ - D = t2.a; - pd = slump[t2.a]; - - if( tri.a == t2.b){ - L3 = t2.ab; - L4 = t2.ac; - } - else{ - L3 = t2.ac; - L4 = t2.ab; - } - } - else{ - cerr << "fuck up at line 13 dude! " << t << endl; - } - - r3 = pts[pd].r; - c3 = pts[pd].c; - dR = tri.R-r3; - dC = tri.C-c3; - - - if( dR*dR+dC*dC < tri.ro ){ // not valid in the Delaunay sense. - L1 = tri.ac; - L2 = tri.bc; - if( L1 != L3 && L2 != L4 ){ // need this check for stability. - - circle_cent2(pts[pa].r, pts[pa].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - - tx.a = tri.c; - tx.b = tri.a; - tx.c = D; - tx.ro = rot; - tx.R = R; - tx.C = C; - - tx.ab = L1; - tx.ac = T2; - tx.bc = L3; - - - // triangle 2; - tx2.a = tri.c; - tx2.b = tri.b; - tx2.c = D; - circle_cent2(pts[pb].r, pts[pb].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - tx2.ro = rot; - tx2.R = R; - tx2.C = C; - - tx2.ab = L2; - tx2.ac = t; - tx2.bc = L4; - - - ids.insert(t); - ids.insert(T2); - - t2 = tx2; - tri = tx; - flipped = 1; - - // change knock on triangle labels. - if( L3 >= 0 ){ - Triad &t3 = triads[L3]; - if( t3.ab == T2 ) t3.ab = t; - else if( t3.bc == T2 ) t3.bc = t; - else if( t3.ac == T2 ) t3.ac = t; - } - - if(L2 >= 0 ){ - Triad &t4 = triads[L2]; - if( t4.ab == t ) t4.ab = T2; - else if( t4.bc == t ) t4.bc = T2; - else if( t4.ac == t ) t4.ac = T2; - } - - } - - } - } - - - if( flipped == 0 && tri.ac >= 0 ){ - - pc = slump[tri.c]; - pb = slump[tri.b]; - pa = slump[tri.a]; - - T2 = tri.ac; - Triad &t2 = triads[T2]; - // find relative orientation (shared limb). - if( t2.ab == t ){ - D = t2.c; - pd = slump[t2.c]; - - if( tri.a == t2.a){ - L3 = t2.ac; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ac; - } - } - else if( t2.ac == t ){ - D = t2.b; - pd = slump[t2.b]; - - if( tri.a == t2.a){ - L3 = t2.ab; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ab; - } - } - else if( t2.bc == t ){ - D = t2.a; - pd = slump[t2.a]; - - if( tri.a == t2.b){ - L3 = t2.ab; - L4 = t2.ac; - } - else{ - L3 = t2.ac; - L4 = t2.ab; - } - } - else{ - cerr << "fuck up at line 14 dude! " << t << endl; - } - - r3 = pts[pd].r; - c3 = pts[pd].c; - dR = tri.R-r3; - dC = tri.C-c3; - - - if( dR*dR+dC*dC < tri.ro ){ // not valid in the Delaunay sense. - L1 = tri.ab; // .ac shared limb - L2 = tri.bc; - if( L1 != L3 && L2 != L4 ){ // need this check for stability. - - circle_cent2(pts[pa].r, pts[pa].c, pts[pb].r, pts[pb].c, r3, c3, R, C , rot); - - tx.a = tri.b; - tx.b = tri.a; - tx.c = D; - tx.ro = rot; - tx.R = R; - tx.C = C; - - tx.ab = L1; - tx.ac = T2; - tx.bc = L3; - - - // triangle 2; - tx2.a = tri.b; - tx2.b = tri.c; - tx2.c = D; - circle_cent2(pts[pb].r, pts[pb].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - tx2.ro = rot; - tx2.R = R; - tx2.C = C; - - tx2.ab = L2; - tx2.ac = t; - tx2.bc = L4; - - ids.insert(t); - ids.insert(T2); - - t2 = tx2; - tri = tx; - - // change knock on triangle labels. - if( L3 >= 0 ){ - Triad &t3 = triads[L3]; - if( t3.ab == T2 ) t3.ab = t; - else if( t3.bc == T2 ) t3.bc = t; - else if( t3.ac == T2 ) t3.ac = t; - } - - if(L2 >= 0 ){ - Triad &t4 = triads[L2]; - if( t4.ab == t ) t4.ab = T2; - else if( t4.bc == t ) t4.bc = T2; - else if( t4.ac == t ) t4.ac = T2; - } - - } - } - } - - //write_Triads(triads, "tflip1.mat"); - int df = 9; - df = 8; - } - - - // cerr << " triangles to resolve " << ids.size() << endl; - - - - - - return; -} - - - - - - - -// same again but with set of triangle ids to be iterated over. - - -void T_flip4( std::vector &pts, std::vector &triads, int *slump, std::set &ids){ - - float R,C,r0,c0, r1,c1, r2,c2, r3,c3, rot, rot2, dR, dC; - int pa,pb,pc, pd, ab, bc, ac, D, L1, L2, L3, L4, T2; - - Triad tx, tx2; - std::set ids2; - ids2.clear(); - - std::set :: const_iterator x=ids.begin(); - while(x != ids.end() ){ - int t = *x; - x++; - - - Triad &tri = triads[t]; - // test all 3 neighbours of tri - int flipped = 0; - - - - if( tri.bc >= 0 ){ - - pa = slump[tri.a]; - pb = slump[tri.b]; - pc = slump[tri.c]; - - T2 = tri.bc; - Triad &t2 = triads[T2]; - // find relative orientation (shared limb). - if( t2.ab == t ){ - D = t2.c; - pd = slump[t2.c]; - - if( tri.b == t2.a){ - L3 = t2.ac; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ac; - } - } - else if( t2.ac == t ){ - D = t2.b; - pd = slump[t2.b]; - - if( tri.b == t2.a){ - L3 = t2.ab; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ab; - } - } - else if( t2.bc == t ){ - D = t2.a; - pd = slump[t2.a]; - - if( tri.b == t2.b){ - L3 = t2.ab; - L4 = t2.ac; - } - else{ - L3 = t2.ac; - L4 = t2.ab; - } - } - else{ - cerr << "fuck up at line 15 dude! t: " << t << " T2: " << T2<< endl; - // tri.prnt(); - //t2.prnt(); - - } - - r3 = pts[pd].r; - c3 = pts[pd].c; - dR = tri.R-r3; - dC = tri.C-c3; - - - if( dR*dR+dC*dC < tri.ro ){ // not valid in the Delaunay sense. - L1 = tri.ab; - L2 = tri.ac; - - if( L1 != L3 && L2 != L4 ){ // need this check for stability. - - circle_cent2(pts[pa].r, pts[pa].c, pts[pb].r, pts[pb].c, r3, c3, R, C , rot); - - tx.a = tri.a; - tx.b = tri.b; - tx.c = D; - tx.ro = rot; - tx.R = R; - tx.C = C; - - tx.ab = L1; - tx.ac = T2; - tx.bc = L3; - - - // triangle 2; - tx2.a = tri.a; - tx2.b = tri.c; - tx2.c = D; - circle_cent2(pts[pa].r, pts[pa].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - tx2.ro = rot; - tx2.R = R; - tx2.C = C; - - tx2.ab = L2; - tx2.ac = t; - tx2.bc = L4; - - ids2.insert(t); - ids2.insert(T2); - - t2 = tx2; - tri = tx; - flipped = 1; - - // change knock on triangle labels. - if( L3 >= 0 ){ - Triad &t3 = triads[L3]; - if( t3.ab == T2 ) t3.ab = t; - else if( t3.bc == T2 ) t3.bc = t; - else if( t3.ac == T2 ) t3.ac = t; - } - - if(L2 >= 0 ){ - Triad &t4 = triads[L2]; - if( t4.ab == t ) t4.ab = T2; - else if( t4.bc == t ) t4.bc = T2; - else if( t4.ac == t ) t4.ac = T2; - } - //if( triads[26777].ab == 27004 && triads[26777].bc == 27004) - // cerr << " feck 1 " << endl; - } - } - } - - - if( flipped == 0 && tri.ab >= 0 ){ - - pc = slump[tri.c]; - pb = slump[tri.b]; - pa = slump[tri.a]; - - T2 = tri.ab; - Triad &t2 = triads[T2]; - // find relative orientation (shared limb). - if( t2.ab == t ){ - D = t2.c; - pd = slump[t2.c]; - - if( tri.a == t2.a){ - L3 = t2.ac; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ac; - } - } - else if( t2.ac == t ){ - D = t2.b; - pd = slump[t2.b]; - - if( tri.a == t2.a){ - L3 = t2.ab; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ab; - } - } - else if( t2.bc == t ){ - D = t2.a; - pd = slump[t2.a]; - - if( tri.a == t2.b){ - L3 = t2.ab; - L4 = t2.ac; - } - else{ - L3 = t2.ac; - L4 = t2.ab; - } - } - else{ - cerr << "fuck up at line 16 dude! " << t << endl; - } - - r3 = pts[pd].r; - c3 = pts[pd].c; - dR = tri.R-r3; - dC = tri.C-c3; - - - if( dR*dR+dC*dC < tri.ro ){ // not valid in the Delaunay sense. - L1 = tri.ac; - L2 = tri.bc; - if( L1 != L3 && L2 != L4 ){ // need this check for stability. - circle_cent2(pts[pa].r, pts[pa].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - - tx.a = tri.c; - tx.b = tri.a; - tx.c = D; - tx.ro = rot; - tx.R = R; - tx.C = C; - - tx.ab = L1; - tx.ac = T2; - tx.bc = L3; - - - // triangle 2; - tx2.a = tri.c; - tx2.b = tri.b; - tx2.c = D; - circle_cent2(pts[pb].r, pts[pb].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - tx2.ro = rot; - tx2.R = R; - tx2.C = C; - - tx2.ab = L2; - tx2.ac = t; - tx2.bc = L4; - - if( (tx.ab == 26777 && tx.ac == 26777 && tx.bc == 26777) || - (tx2.ab == 26777 && tx2.ac == 26777 && tx2.bc == 26777) ){ - int foon = 8; - } - - - ids2.insert(t); - ids2.insert(T2); - - t2 = tx2; - tri = tx; - flipped = 1; - - // change knock on triangle labels. - if( L3 >= 0 ){ - Triad &t3 = triads[L3]; - if( t3.ab == T2 ) t3.ab = t; - else if( t3.bc == T2 ) t3.bc = t; - else if( t3.ac == T2 ) t3.ac = t; - } - - if(L2 >= 0 ){ - Triad &t4 = triads[L2]; - if( t4.ab == t ) t4.ab = T2; - else if( t4.bc == t ) t4.bc = T2; - else if( t4.ac == t ) t4.ac = T2; - } - ///if( triads[26777].ab == 27004 && triads[26777].bc == 27004) - // cerr << " feck 2 " << endl; - } - } - } - - - if( flipped == 0 && tri.ac >= 0 ){ - - pc = slump[tri.c]; - pb = slump[tri.b]; - pa = slump[tri.a]; - - T2 = tri.ac; - Triad &t2 = triads[T2]; - // find relative orientation (shared limb). - if( t2.ab == t ){ - D = t2.c; - pd = slump[t2.c]; - - if( tri.a == t2.a){ - L3 = t2.ac; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ac; - } - } - else if( t2.ac == t ){ - D = t2.b; - pd = slump[t2.b]; - - if( tri.a == t2.a){ - L3 = t2.ab; - L4 = t2.bc; - } - else{ - L3 = t2.bc; - L4 = t2.ab; - } - } - else if( t2.bc == t ){ - D = t2.a; - pd = slump[t2.a]; - - if( tri.a == t2.b){ - L3 = t2.ab; - L4 = t2.ac; - } - else{ - L3 = t2.ac; - L4 = t2.ab; - } - } - else{ - cerr << "fuck up at line 17 dude! " << t << endl; - } - - r3 = pts[pd].r; - c3 = pts[pd].c; - dR = tri.R-r3; - dC = tri.C-c3; - - float scubit = dR*dR+dC*dC - tri.ro; - - if( scubit < 0.0 ){ // not valid in the Delaunay sense. - L1 = tri.ab; // .ac shared limb - L2 = tri.bc; - if( L1 != L3 && L2 != L4 ){ // need this check for stability. - - if( -scubit*1000 > tri.ro ) - circle_cent2(pts[pa].r, pts[pa].c, pts[pb].r, pts[pb].c, r3, c3, R, C , rot); - else{ - circle_cent4(pts[pa].r, pts[pa].c, pts[pb].r, pts[pb].c, r3, c3, R, C , rot); - //cerr << "duff " << t << " scubit " << scubit << endl; - } - - tx.a = tri.b; - tx.b = tri.a; - tx.c = D; - tx.ro = rot; - tx.R = R; - tx.C = C; - - tx.ab = L1; - tx.ac = T2; - tx.bc = L3; - - - // triangle 2; - tx2.a = tri.b; - tx2.b = tri.c; - tx2.c = D; - - - if( -scubit*1000 > tri.ro ) - circle_cent2(pts[pb].r, pts[pb].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - else{ - circle_cent2(pts[pb].r, pts[pb].c, pts[pc].r, pts[pc].c, r3, c3, R, C , rot); - //cerr << "duff " << t << " scubit " << scubit << endl; - } - - tx2.ro = rot; - tx2.R = R; - tx2.C = C; - - tx2.ab = L2; - tx2.ac = t; - tx2.bc = L4; - - - ids2.insert(t); - ids2.insert(T2); - - t2 = tx2; - tri = tx; - - // change knock on triangle labels. - if( L3 >= 0 ){ - Triad &t3 = triads[L3]; - if( t3.ab == T2 ) t3.ab = t; - else if( t3.bc == T2 ) t3.bc = t; - else if( t3.ac == T2 ) t3.ac = t; - } - - if(L2 >= 0 ){ - Triad &t4 = triads[L2]; - if( t4.ab == t ) t4.ab = T2; - else if( t4.bc == t ) t4.bc = T2; - else if( t4.ac == t ) t4.ac = T2; - } - - //if( triads[26777].ab == 27004 && triads[26777].bc == 27004) - // cerr << " feck 3" << endl; - } - } - } - - //write_Triads(triads, "tflip1.mat"); - int df = 9; - df = 8; - } - - - // cerr << " triangles to resolve " << ids2.size() << endl; - ids.clear(); - ids.insert(ids2.begin(), ids2.end()); - - return; -} - - -void circle_cent4(float r1,float c1, float r2,float c2, float r3,float c3, - float &r,float &c, float &ro2){ - /* - * function to return the center of a circle and its radius - * degenerate case should never be passed to this routine!!!!!!!!!!!!! - * but will return r0 = -1 if it is. - */ - - double rd, cd; - double v1 = 2*(r2-r1), v2 = 2*(c2-c1), v3 = r2*r2 - r1*r1 + c2*c2 - c1*c1; - double v4 = 2*(r3-r1), - v5 = 2*(c3-c1), - v6 = r3*r3 - r1*r1 + c3*c3 - c1*c1, - - v7 = v2*v4 - v1*v5; - if( v7 == 0 ){ - r=0; - c=0; - ro2 = -1; - return; - } - - cd = (v4*v3 - v1*v6)/v7; - if( v1 != 0 ) - rd = (v3 - c*v2)/v1; - else - rd = (v6 - c*v5)/v4; - - ro2 = (float) ( (rd-r1)*(rd-r1) + (cd-c1)*(cd-c1) ); - r = (float) rd; - c = (float) cd; - - return; -} diff --git a/src/s_hull/s_hull.h b/src/s_hull/s_hull.h deleted file mode 100644 index d2060eb..0000000 --- a/src/s_hull/s_hull.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef _structures_h -#define _structures_h - - - - -// for FILE - -#include -#include -#include - - - -/* - for use in s_hull.C - -S-hull, Copyright (c) 2010 -Dr David SInclair -Cambridge, UK - -email david@s-hull.org - -The software includes the S-hull programs. -S-hull is copyrighted as above. -S-hull is free software and may be obtained from www.s-hull.org. -It may be freely copied, modified, -and redistributed under the following conditions: - -S-hull is free software and may be obtained from www.s-hull.org. -It may be freely copied, modified, -and redistributed under the following conditions which might loosely be termed a contribtors beerware license: -1. All copyright notices must remain intact in all files. -2. A copy of this text file must be distributed along with any copies - of S-hull that you redistribute; this includes copies that you have - modified, or copies of programs or other software products that - include S-hull where distributed as source. - -3. If you modify S-hull, you must include a notice giving the - name of the person performing the modification, the date of - modification, and the reason for such modification. - -4. If you are distributing a binary or compiled version of s-hull it - is not necessary to include any acknowledgement or reference - to s-hull. -5. There is no warranty or other guarantee of fitness for S-hull, it is - provided solely "as is". Bug reports or fixes may be sent to - bugs@s-hull.org; the authors may or may not act on them as - they desire. -6. By copying or compliing the code for S-hull you explicitly indemnify -the copyright holder against any liability he may incur as a result of you -copying the code. - -7. If you meet any of the contributors to the code you used from s-hull.org - in a pub or a bar, and you think the source code they contributed to is worth it, - you can buy them a beer. - - If your principles run against beer a bacon-double-cheeseburger would do just as nicely - or you could email david@s-hull.org and arrange to make a donation of 10 of your local currancy units - to support s-hull.org. - - -*/ - -struct Triad -{ - int a,b, c; - int ab, bc, ac; // adjacent edges index to neighbouring triangle. - float ro, R,C; - //std::set idx; - Triad() {}; -Triad(int x, int y) : a(x), b(y),c(0), ab(-1), bc(-1), ac(-1), ro(-1), R(0), C(0) {}; -Triad(int x, int y, int z) : a(x), b(y), c(z), ab(-1), bc(-1), ac(-1), ro(-1), R(0), C(0) {}; -Triad(const Triad &p) : a(p.a), b(p.b), c(p.c), ab(p.ab), bc(p.bc), ac(p.ac), ro(p.ro), R(p.R), C(p.C) {}; - - Triad &operator=(const Triad &p) - { - a = p.a; - b = p.b; - c = p.c; - - ab = p.ab; - bc = p.bc; - ac = p.ac; - - ro = p.ro; - R = p.R; - C = p.C; - - return *this; - }; - void prnt(){ - cerr << a << " " << b << " " << c << " " << ab << " " << ac << " " << bc << endl; - }; -}; - - - -/* point structure for s_hull only. - has to keep track of triangle ids as hull evolves. - - -*/ - - -struct Shx -{ - int id, trid; - float r,c , tr, tc; - float ro; - Shx() {}; - Shx(int a, int b) : r(a), c(b), ro(0), id(-1) {}; - Shx(int a, int b, float x) : r(a), c(b), ro(x), id(-1) {}; - Shx(const Shx &p) : id(p.id), trid(p.trid), r(p.r), c(p.c), tr(p.tr), tc(p.tc), ro(p.ro) {}; - - Shx &operator=(const Shx &p) - { - id = p.id; - trid = p.trid; - r = p.r; - c = p.c; - tr = p.tr; - tc = p.tc; - ro = p.ro; - return *this; - }; - -}; - -//inline bool operator==(const Shx &a, const Shx &b) -//{ -// return a.r == b.r && a.c == b.c; -//}; - -// sort into descending order (for use in corner responce ranking). -inline bool operator<(const Shx &a, const Shx &b) -{ - if( a.ro == b.ro) - return a.r < b.r; - return a.ro < b.ro; -}; - - - -// from s_hull.C - - -void s_hull_del_ray2( std::vector &pts, std::vector &triads); -void circle_cent2(float r1,float c1, float r2,float c2, float r3,float c3,float &r,float &c, float &ro2); -void circle_cent4(float r1,float c1, float r2,float c2, float r3,float c3,float &r,float &c, float &ro2); -void write_Shx(std::vector &pts, char * fname); -void write_Triads(std::vector &ts, char * fname); -void T_flip2( std::vector &pts, std::vector &triads, int *slump, int numt, int start); -void T_flip3( std::vector &pts, std::vector &triads, int *slump, int numt, int start,std::set &ids ); -void T_flip4( std::vector &pts, std::vector &triads, int *slump, std::set &ids); - - - -#endif diff --git a/src/s_hull/s_hull_pro.cpp b/src/s_hull/s_hull_pro.cpp new file mode 100644 index 0000000..dbe32f3 --- /dev/null +++ b/src/s_hull/s_hull_pro.cpp @@ -0,0 +1,1676 @@ +#include +//#include +//#include +#include +#include +#include +#include +#include +#include +#include + + +#include "s_hull_pro.h" + +using namespace std; + + +/* copyright 2012 Dr David Sinclair + david@s-hull.org + + program to compute Delaunay triangulation of a set of points. + + this code may not be published or distributed without the concent of the copyright holder. + + */ + + + + +void circle_cent2(float r1,float c1, float r2,float c2, float r3,float c3, + float &r,float &c, float &ro2) +{ + /* + * function to return the center of a circle and its radius + * degenerate case should never be passed to this routine!!!!!!!!!!!!! + * but will return r0 = -1 if it is. + */ + + float v1 = 2*(r2-r1), v2 = 2*(c2-c1), v3 = r2*r2 - r1*r1 + c2*c2 - c1*c1; + float v4 = 2*(r3-r1), + v5 = 2*(c3-c1), + v6 = r3*r3 - r1*r1 + c3*c3 - c1*c1, + + v7 = v2*v4 - v1*v5; + if( v7 == 0 ) + { + r=0; + c=0; + ro2 = -1; + return; + } + + c = (v4*v3 - v1*v6)/v7; + if( v1 != 0 ) + r = (v3 - c*v2)/v1; + else + r = (v6 - c*v5)/v4; + + ro2 = ( (r-r1)*(r-r1) + (c-c1)*(c-c1) ); + + return; +} + + +/* + read an ascii file of (r,c) point pairs. + + the first line of the points file should contain + "NUMP 2 points" + + if it does not have the word points in it the first line is + interpretted as a point pair. + + */ + +int read_Shx(std::vector &pts, char * fname) +{ + char s0[513]; + int nump =0; + float p1,p2; + + Shx pt; + + std::string line; + std::string points_str("points"); + + std::ifstream myfile; + myfile.open(fname); + + if (myfile.is_open()) + { + + getline (myfile,line); + //int numc = line.length(); + + // check string for the string "points" + int n = (int) line.find( points_str); + if( n > 0) + { + while ( myfile.good() ) + { + getline (myfile,line); + if( line.length() <= 512) + { + copy( line.begin(), line.end(), s0); + s0[line.length()] = 0; + int v = sscanf( s0, "%g %g", &p1,&p2); + if( v>0 ) + { + pt.id = nump; + nump++; + pt.r = p1; + pt.c = p2; + pts.push_back(pt); + } + } + } + } + else // assume all number pairs on a line are points + { + if( line.length() <= 512) + { + copy( line.begin(), line.end(), s0); + s0[line.length()] = 0; + int v = sscanf( s0, "%g %g", &p1,&p2); + if( v>0 ) + { + pt.id = nump; + nump++; + pt.r = p1; + pt.c = p2; + pts.push_back(pt); + } + } + + while ( myfile.good() ) + { + getline (myfile,line); + if( line.length() <= 512) + { + copy( line.begin(), line.end(), s0); + s0[line.length()] = 0; + int v = sscanf( s0, "%g %g", &p1,&p2); + if( v>0 ) + { + pt.id = nump; + nump++; + pt.r = p1; + pt.c = p2; + pts.push_back(pt); + } + } + } + } + myfile.close(); + } + + nump = (int) pts.size(); + + return(nump); +}; + +/* + write out a set of points to disk + + +*/ + +void write_Shx(std::vector &pts, char * fname) +{ + std::ofstream out(fname, ios::out); + + int nr = (int) pts.size(); + out << nr << " 2 points" << endl; + + for (int r = 0; r < nr; r++) + { + out << pts[r].r << ' ' << pts[r].c << endl; + } + out.close(); + + return; +}; + + + +/* + write out triangle ids to be compatible with matlab/octave array numbering. + + */ +void write_Triads(std::vector &ts, char * fname) +{ + std::ofstream out(fname, ios::out); + + int nr = (int) ts.size(); + out << nr << " 6 point-ids (1,2,3) adjacent triangle-ids ( limbs ab ac bc )" << endl; + + for (int r = 0; r < nr; r++) + { + out << ts[r].a+1 << ' ' << ts[r].b+1 <<' ' << ts[r].c+1 <<' ' + << ts[r].ab+1 <<' ' << ts[r].ac+1 <<' ' << ts[r].bc+1 << endl; //" " << ts[r].ro << endl; + } + out.close(); + + return; +}; + + + + + +/* version in which the ids of the triangles associated with the sides of the hull are tracked. + + + */ + +int s_hull_pro( std::vector &pts, std::vector &triads) +{ + + int nump = (int) pts.size(); + + if( nump < 3 ) + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "less than 3 points, aborting " << endl; + return(-1); + } + + + float r = pts[0].r; + float c = pts[0].c; + for( int k=0; k 0 ) + { + mid = k; + romin2 = ro2; + R = r; + C = c; + + } + else if( romin2 *4 < pts[k].ro ) + k=nump; + + k++; + } + + if( mid < 0 ) + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "linear structure, aborting " << endl; + return(-2); + } + + + Shx pt0 = pts[0]; + Shx pt1 = pts[1]; + Shx pt2 = pts[mid]; + + pts.erase(pts.begin() + mid); // necessary for round off reasons:(((((( + pts.erase(pts.begin() ); + pts.erase(pts.begin() ); + + for( int k=0; k slump; + slump.resize(nump); + + for( int k=0; k hull; + + + r = (pts[0].r + pts[1].r + pts[2].r )/(float) 3.0; + c = (pts[0].c + pts[1].c + pts[2].c )/(float) 3.0; + + float dr0 = pts[0].r - r, dc0 = pts[0].c - c; + float tr01 = pts[1].r - pts[0].r, tc01 = pts[1].c - pts[0].c; + + float df = -tr01* dc0 + tc01*dr0; + if( df < 0 ) // [ 0 1 2 ] + { + pt0.tr = pt1.r-pt0.r; + pt0.tc = pt1.c-pt0.c; + pt0.trid = 0; + hull.push_back( pt0 ); + + pt1.tr = pt2.r-pt1.r; + pt1.tc = pt2.c-pt1.c; + pt1.trid = 0; + hull.push_back( pt1 ); + + pt2.tr = pt0.r-pt2.r; + pt2.tc = pt0.c-pt2.c; + pt2.trid = 0; + hull.push_back( pt2 ); + + + Triad tri(pt0.id,pt1.id,pt2.id); + tri.ro = romin2; + tri.R = R; + tri.C = C; + + triads.push_back(tri); + + } + else // [ 0 2 1 ] as anti-clockwise turning is the work of the devil.... + { + pt0.tr = pt2.r-pt0.r; + pt0.tc = pt2.c-pt0.c; + pt0.trid = 0; + hull.push_back( pt0 ); + + pt2.tr = pt1.r-pt2.r; + pt2.tc = pt1.c-pt2.c; + pt2.trid = 0; + hull.push_back( pt2 ); + + pt1.tr = pt0.r-pt1.r; + pt1.tc = pt0.c-pt1.c; + pt1.trid = 0; + hull.push_back( pt1 ); + + Triad tri(pt0.id,pt2.id,pt1.id); + tri.ro = romin2; + tri.R = R; + tri.C = C; + triads.push_back(tri); + } + + // add new points into hull (removing obscured ones from the chain) + // and creating triangles.... + // that will need to be flipped. + + float dr, dc, rx,cx; + Shx ptx; + int numt=0; // added by A.Balakin 6 July 2012 -- uninitialised variable + + for( int k=3; k pidx, tridx; + int hidx; // new hull point location within hull..... + + + float df = -dc* hull[0].tr + dr*hull[0].tc; // visibility test vector. + if( df < 0 ) // starting with a visible hull facet !!! + { +// int e1 = 1, e2 = numh; // commented by A.Balakin 6 July 2012 -- unused variable + hidx = 0; + + // check to see if segment numh is also visible + df = -dc* hull[numh-1].tr + dr*hull[numh-1].tc; + //cerr << df << ' ' ; + if( df < 0 ) // visible. + { + pidx.push_back(hull[numh-1].id); + tridx.push_back(hull[numh-1].trid); + + + for( int h=0; h0; h--) + { + // if segment h is visible delete h + 1 + dr = rx- hull[h].r; + dc = cx- hull[h].c; + df = -dc* hull[h].tr + dr*hull[h].tc; + + if( df < 0 ) // h is visible + { + pidx.insert(pidx.begin(), hull[h].id); + tridx.insert(tridx.begin(), hull[h].trid); + hull.erase(hull.begin() + h+1); // erase end of chain + + } + else + { + + h = (int) hull.size()-1; + hull[h].tr = -hull[h].r + ptx.r; // points at start of chain. + hull[h].tc = -hull[h].c + ptx.c; + break; + } + } + + df = 9; + + } + else + { + // cerr << df << ' ' << endl; + hidx = 1; // keep pt hull[0] + tridx.push_back(hull[0].trid); + pidx.push_back(hull[0].id); + + for( int h=1; h 0 ) // first invisible segment. + { + e2 = h; + break; + } + } + + } + + + // triangle pidx starts at e1 and ends at e2 (inclusive). + if( e2 < numh ) + { + for( int e=e1; e<=e2; e++) + { + pidx.push_back(hull[e].id); + tridx.push_back(hull[e].trid); + } + } + else + { + for( int e=e1; e 0 ) + hull[hidx-1].trid = numt; + else + { + numh = (int) hull.size(); + hull[numh-1].trid = numt; + } + triads.push_back( trx ); + numt++; + } + + else + { + trx.ab = -1; + for(int p=0; p 0 ) + trx.ab = numt-1; + trx.ac = numt+1; + + // index back into the triads. + Triad &txx = triads[tridx[p]]; + if( ( trx.b == txx.a && trx.c == txx.b) |( trx.b == txx.b && trx.c == txx.a)) + { + txx.ab = numt; + } + else if( ( trx.b == txx.a && trx.c == txx.c) |( trx.b == txx.c && trx.c == txx.a)) + { + txx.ac = numt; + } + else if( ( trx.b == txx.b && trx.c == txx.c) |( trx.b == txx.c && trx.c == txx.b)) + { + txx.bc = numt; + } + + triads.push_back( trx ); + numt++; + } + triads[numt-1].ac=-1; + + hull[hidx].trid = numt-1; + if( hidx > 0 ) + hull[hidx-1].trid = T0; + else + { + numh = (int) hull.size(); + hull[numh-1].trid = T0; + } + + + } + + } + +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "of triangles " << triads.size() << " to be flipped. "<< endl; + + // write_Triads(triads, "tris0.mat"); + + std::set ids, ids2; + + int tf = T_flip_pro( pts, triads, slump, numt, 0, ids); + if( tf < 0 ) + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "cannot triangualte this set " << endl; + return(-3); + } + + // write_Triads(triads, "tris1.mat"); + + int nits = (int) ids.size(), nit=1; + while( nits > 0 && nit < 50) + { + + tf = T_flip_pro_idx( pts, triads, slump, ids); + nits = (int) ids.size(); + nit ++; + if( tf < 0 ) + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "cannot triangualte this set " << endl; + return(-4); + } + } + return(1); +} + + +void circle_cent4(float r1,float c1, float r2,float c2, float r3,float c3, + float &r,float &c, float &ro2) +{ + /* + * function to return the center of a circle and its radius + * degenerate case should never be passed to this routine!!!!!!!!!!!!! + * but will return r0 = -1 if it is. + */ + + double rd, cd; + double v1 = 2*(r2-r1), v2 = 2*(c2-c1), v3 = r2*r2 - r1*r1 + c2*c2 - c1*c1; + double v4 = 2*(r3-r1), + v5 = 2*(c3-c1), + v6 = r3*r3 - r1*r1 + c3*c3 - c1*c1, + + v7 = v2*v4 - v1*v5; + if( v7 == 0 ) + { + r=0; + c=0; + ro2 = -1; + return; + } + + cd = (v4*v3 - v1*v6)/v7; + if( v1 != 0 ) + rd = (v3 - c*v2)/v1; + else + rd = (v6 - c*v5)/v4; + + ro2 = (float) ( (rd-r1)*(rd-r1) + (cd-c1)*(cd-c1) ); + r = (float) rd; + c = (float) cd; + + return; +} + + +/* test a set of points for duplicates. + + erase duplicate points, do not change point ids. + +*/ + +int de_duplicate( std::vector &pts, std::vector &outx ) +{ + + int nump = (int) pts.size(); + std::vector dpx; + Dupex d; + for( int k=0; k=0; k--) + { + pts.erase(pts.begin()+outx[k]); + } + + return(nx); +} + + + + +/* + flip pairs of triangles that are not valid delaunay triangles + the Cline-Renka test is used rather than the less stable circum + circle center computation test of s-hull. + + or the more expensive determinant test. + + */ + + +int T_flip_pro( std::vector &pts, std::vector &triads, std::vector &slump, int numt, int start, std::set &ids) +{ + + float r3,c3; + int pa,pb,pc, pd, D, L1, L2, L3, L4, T2; + + Triad tx, tx2; + + + for( int t=start; t= 0 ) + { + + pa = slump[tri.a]; + pb = slump[tri.b]; + pc = slump[tri.c]; + + T2 = tri.bc; + Triad &t2 = triads[T2]; + // find relative orientation (shared limb). + if( t2.ab == t ) + { + D = t2.c; + pd = slump[t2.c]; + + if( tri.b == t2.a) + { + L3 = t2.ac; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ac; + } + } + else if( t2.ac == t ) + { + D = t2.b; + pd = slump[t2.b]; + + if( tri.b == t2.a) + { + L3 = t2.ab; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ab; + } + } + else if( t2.bc == t ) + { + D = t2.a; + pd = slump[t2.a]; + + if( tri.b == t2.b) + { + L3 = t2.ab; + L4 = t2.ac; + } + else + { + L3 = t2.ac; + L4 = t2.ab; + } + } + else + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "triangle flipping error. " << t << endl; + return(-5); + } + + r3 = pts[pd].r; + c3 = pts[pd].c; + + int XX = Cline_Renka_test( pts[pa].r, pts[pa].c, pts[pb].r, pts[pb].c, + pts[pc].r, pts[pc].c, r3, c3 ); + + if( XX < 0 ) + { + + L1 = tri.ab; + L2 = tri.ac; + if( L1 != L3 && L2 != L4 ) // need this check for stability. + { + + tx.a = tri.a; + tx.b = tri.b; + tx.c = D; + + tx.ab = L1; + tx.ac = T2; + tx.bc = L3; + + + // triangle 2; + tx2.a = tri.a; + tx2.b = tri.c; + tx2.c = D; + + tx2.ab = L2; + tx2.ac = t; + tx2.bc = L4; + + + ids.insert(t); + ids.insert(T2); + + t2 = tx2; + tri = tx; + flipped = 1; + + // change knock on triangle labels. + if( L3 >= 0 ) + { + Triad &t3 = triads[L3]; + if( t3.ab == T2 ) t3.ab = t; + else if( t3.bc == T2 ) t3.bc = t; + else if( t3.ac == T2 ) t3.ac = t; + } + + if(L2 >= 0 ) + { + Triad &t4 = triads[L2]; + if( t4.ab == t ) t4.ab = T2; + else if( t4.bc == t ) t4.bc = T2; + else if( t4.ac == t ) t4.ac = T2; + } + } + } + } + + + if( flipped == 0 && tri.ab >= 0 ) + { + + pc = slump[tri.c]; + pb = slump[tri.b]; + pa = slump[tri.a]; + + T2 = tri.ab; + Triad &t2 = triads[T2]; + // find relative orientation (shared limb). + if( t2.ab == t ) + { + D = t2.c; + pd = slump[t2.c]; + + if( tri.a == t2.a) + { + L3 = t2.ac; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ac; + } + } + else if( t2.ac == t ) + { + D = t2.b; + pd = slump[t2.b]; + + if( tri.a == t2.a) + { + L3 = t2.ab; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ab; + } + } + else if( t2.bc == t ) + { + D = t2.a; + pd = slump[t2.a]; + + if( tri.a == t2.b) + { + L3 = t2.ab; + L4 = t2.ac; + } + else + { + L3 = t2.ac; + L4 = t2.ab; + } + } + else + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "triangle flipping error. " << t << endl; + return(-5); + } + + r3 = pts[pd].r; + c3 = pts[pd].c; + + int XX = Cline_Renka_test( pts[pc].r, pts[pc].c, pts[pb].r, pts[pb].c, + pts[pa].r, pts[pa].c,r3, c3); + + if( XX < 0) + { + + + L1 = tri.ac; + L2 = tri.bc; + if( L1 != L3 && L2 != L4 ) // need this check for stability. + { + + tx.a = tri.c; + tx.b = tri.a; + tx.c = D; + + tx.ab = L1; + tx.ac = T2; + tx.bc = L3; + + + // triangle 2; + tx2.a = tri.c; + tx2.b = tri.b; + tx2.c = D; + + tx2.ab = L2; + tx2.ac = t; + tx2.bc = L4; + + + ids.insert(t); + ids.insert(T2); + + t2 = tx2; + tri = tx; + flipped = 1; + + // change knock on triangle labels. + if( L3 >= 0 ) + { + Triad &t3 = triads[L3]; + if( t3.ab == T2 ) t3.ab = t; + else if( t3.bc == T2 ) t3.bc = t; + else if( t3.ac == T2 ) t3.ac = t; + } + + if(L2 >= 0 ) + { + Triad &t4 = triads[L2]; + if( t4.ab == t ) t4.ab = T2; + else if( t4.bc == t ) t4.bc = T2; + else if( t4.ac == t ) t4.ac = T2; + } + + } + + } + } + + + if( flipped == 0 && tri.ac >= 0 ) + { + + pc = slump[tri.c]; + pb = slump[tri.b]; + pa = slump[tri.a]; + + T2 = tri.ac; + Triad &t2 = triads[T2]; + // find relative orientation (shared limb). + if( t2.ab == t ) + { + D = t2.c; + pd = slump[t2.c]; + + if( tri.a == t2.a) + { + L3 = t2.ac; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ac; + } + } + else if( t2.ac == t ) + { + D = t2.b; + pd = slump[t2.b]; + + if( tri.a == t2.a) + { + L3 = t2.ab; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ab; + } + } + else if( t2.bc == t ) + { + D = t2.a; + pd = slump[t2.a]; + + if( tri.a == t2.b) + { + L3 = t2.ab; + L4 = t2.ac; + } + else + { + L3 = t2.ac; + L4 = t2.ab; + } + } + else + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "triangle flipping error. " << t << endl; + return(-5); + } + + r3 = pts[pd].r; + c3 = pts[pd].c; + + int XX = Cline_Renka_test( pts[pb].r, pts[pb].c, pts[pa].r, pts[pa].c, + pts[pc].r, pts[pc].c,r3, c3); + + if( XX < 0 ) + { + + L1 = tri.ab; // .ac shared limb + L2 = tri.bc; + if( L1 != L3 && L2 != L4 ) // need this check for stability. + { + + tx.a = tri.b; + tx.b = tri.a; + tx.c = D; + + tx.ab = L1; + tx.ac = T2; + tx.bc = L3; + + + // triangle 2; + tx2.a = tri.b; + tx2.b = tri.c; + tx2.c = D; + + tx2.ab = L2; + tx2.ac = t; + tx2.bc = L4; + + ids.insert(t); + ids.insert(T2); + + t2 = tx2; + tri = tx; + + // change knock on triangle labels. + if( L3 >= 0 ) + { + Triad &t3 = triads[L3]; + if( t3.ab == T2 ) t3.ab = t; + else if( t3.bc == T2 ) t3.bc = t; + else if( t3.ac == T2 ) t3.ac = t; + } + + if(L2 >= 0 ) + { + Triad &t4 = triads[L2]; + if( t4.ab == t ) t4.ab = T2; + else if( t4.bc == t ) t4.bc = T2; + else if( t4.ac == t ) t4.ac = T2; + } + + } + } + } + + + } + + + return(1); +} + +/* minimum angle cnatraint for circum circle test. + due to Cline & Renka + + A -- B + + | / | + + C -- D + + + */ + +int Cline_Renka_test(float &Ax, float &Ay, + float &Bx, float &By, + float &Cx, float &Cy, + float &Dx, float &Dy) +{ + + float v1x = Bx-Ax, v1y = By-Ay, v2x = Cx-Ax, v2y = Cy-Ay, + v3x = Bx-Dx, v3y = By-Dy, v4x = Cx-Dx, v4y = Cy-Dy; + float cosA = v1x*v2x + v1y*v2y; + float cosD = v3x*v4x + v3y*v4y; + + if( cosA < 0 && cosD < 0 ) // two obtuse angles + return(-1); + +// float ADX = Ax-Dx, ADy = Ay-Dy; // commented by A.Balakin 6 July 2012 -- unused variable + + + if( cosA > 0 && cosD > 0 ) // two acute angles + return(1); + + + float sinA = fabs(v1x*v2y - v1y*v2x); + float sinD = fabs(v3x*v4y - v3y*v4x); + + if( cosA*sinD + sinA*cosD < 0 ) + return(-1); + + return(1); + +} + + + + +// same again but with set of triangle ids to be iterated over. + + +int T_flip_pro_idx( std::vector &pts, std::vector &triads, std::vector &slump, std::set &ids) +{ + + float r3,c3; + int pa,pb,pc, pd, D, L1, L2, L3, L4, T2; + + Triad tx, tx2; + std::set ids2; + ids2.clear(); + + std::set :: const_iterator x=ids.begin(); + while(x != ids.end() ) + { + int t = *x; + x++; + + + Triad &tri = triads[t]; + // test all 3 neighbours of tri + int flipped = 0; + + + + if( tri.bc >= 0 ) + { + + pa = slump[tri.a]; + pb = slump[tri.b]; + pc = slump[tri.c]; + + T2 = tri.bc; + Triad &t2 = triads[T2]; + // find relative orientation (shared limb). + if( t2.ab == t ) + { + D = t2.c; + pd = slump[t2.c]; + + if( tri.b == t2.a) + { + L3 = t2.ac; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ac; + } + } + else if( t2.ac == t ) + { + D = t2.b; + pd = slump[t2.b]; + + if( tri.b == t2.a) + { + L3 = t2.ab; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ab; + } + } + else if( t2.bc == t ) + { + D = t2.a; + pd = slump[t2.a]; + + if( tri.b == t2.b) + { + L3 = t2.ab; + L4 = t2.ac; + } + else + { + L3 = t2.ac; + L4 = t2.ab; + } + } + else + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "triangle flipping error. " << t << " T2: " << T2<< endl; + return(-6); + } + + r3 = pts[pd].r; + c3 = pts[pd].c; + + int XX = Cline_Renka_test( pts[pa].r, pts[pa].c, pts[pb].r, pts[pb].c, + pts[pc].r, pts[pc].c,r3, c3); + + if( XX < 0 ) + { + L1 = tri.ab; + L2 = tri.ac; + + if( L1 != L3 && L2 != L4 ) // need this check for stability. + { + + + tx.a = tri.a; + tx.b = tri.b; + tx.c = D; + + tx.ab = L1; + tx.ac = T2; + tx.bc = L3; + + + // triangle 2; + tx2.a = tri.a; + tx2.b = tri.c; + tx2.c = D; + + tx2.ab = L2; + tx2.ac = t; + tx2.bc = L4; + + ids2.insert(t); + ids2.insert(T2); + + t2 = tx2; + tri = tx; + flipped = 1; + + // change knock on triangle labels. + if( L3 >= 0 ) + { + Triad &t3 = triads[L3]; + if( t3.ab == T2 ) t3.ab = t; + else if( t3.bc == T2 ) t3.bc = t; + else if( t3.ac == T2 ) t3.ac = t; + } + + if(L2 >= 0 ) + { + Triad &t4 = triads[L2]; + if( t4.ab == t ) t4.ab = T2; + else if( t4.bc == t ) t4.bc = T2; + else if( t4.ac == t ) t4.ac = T2; + } + + } + } + } + + + if( flipped == 0 && tri.ab >= 0 ) + { + + pc = slump[tri.c]; + pb = slump[tri.b]; + pa = slump[tri.a]; + + T2 = tri.ab; + Triad &t2 = triads[T2]; + // find relative orientation (shared limb). + if( t2.ab == t ) + { + D = t2.c; + pd = slump[t2.c]; + + if( tri.a == t2.a) + { + L3 = t2.ac; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ac; + } + } + else if( t2.ac == t ) + { + D = t2.b; + pd = slump[t2.b]; + + if( tri.a == t2.a) + { + L3 = t2.ab; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ab; + } + } + else if( t2.bc == t ) + { + D = t2.a; + pd = slump[t2.a]; + + if( tri.a == t2.b) + { + L3 = t2.ab; + L4 = t2.ac; + } + else + { + L3 = t2.ac; + L4 = t2.ab; + } + } + else + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "triangle flipping error. " << t << endl; + return(-6); + } + + r3 = pts[pd].r; + c3 = pts[pd].c; + + int XX = Cline_Renka_test( pts[pc].r, pts[pc].c, pts[pb].r, pts[pb].c, + pts[pa].r, pts[pa].c,r3, c3); + + if( XX < 0 ) + { + L1 = tri.ac; + L2 = tri.bc; + if( L1 != L3 && L2 != L4 ) // need this check for stability. + { + + tx.a = tri.c; + tx.b = tri.a; + tx.c = D; + + tx.ab = L1; + tx.ac = T2; + tx.bc = L3; + + + // triangle 2; + tx2.a = tri.c; + tx2.b = tri.b; + tx2.c = D; + + tx2.ab = L2; + tx2.ac = t; + tx2.bc = L4; + + + ids2.insert(t); + ids2.insert(T2); + + t2 = tx2; + tri = tx; + flipped = 1; + + // change knock on triangle labels. + if( L3 >= 0 ) + { + Triad &t3 = triads[L3]; + if( t3.ab == T2 ) t3.ab = t; + else if( t3.bc == T2 ) t3.bc = t; + else if( t3.ac == T2 ) t3.ac = t; + } + + if(L2 >= 0 ) + { + Triad &t4 = triads[L2]; + if( t4.ab == t ) t4.ab = T2; + else if( t4.bc == t ) t4.bc = T2; + else if( t4.ac == t ) t4.ac = T2; + } + + } + } + } + + + if( flipped == 0 && tri.ac >= 0 ) + { + + pc = slump[tri.c]; + pb = slump[tri.b]; + pa = slump[tri.a]; + + T2 = tri.ac; + Triad &t2 = triads[T2]; + // find relative orientation (shared limb). + if( t2.ab == t ) + { + D = t2.c; + pd = slump[t2.c]; + + if( tri.a == t2.a) + { + L3 = t2.ac; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ac; + } + } + else if( t2.ac == t ) + { + D = t2.b; + pd = slump[t2.b]; + + if( tri.a == t2.a) + { + L3 = t2.ab; + L4 = t2.bc; + } + else + { + L3 = t2.bc; + L4 = t2.ab; + } + } + else if( t2.bc == t ) + { + D = t2.a; + pd = slump[t2.a]; + + if( tri.a == t2.b) + { + L3 = t2.ab; + L4 = t2.ac; + } + else + { + L3 = t2.ac; + L4 = t2.ab; + } + } + else + { +// Commented by A.Balakin 2 July 2012 -- library shouldn't print anything +// cerr << "triangle flipping error. " << t << endl; + return(-6); + } + + r3 = pts[pd].r; + c3 = pts[pd].c; + + int XX = Cline_Renka_test( pts[pb].r, pts[pb].c, pts[pc].r, pts[pc].c, + pts[pa].r, pts[pa].c,r3, c3); + + if( XX < 0 ) + { + L1 = tri.ab; // .ac shared limb + L2 = tri.bc; + if( L1 != L3 && L2 != L4 ) // need this check for stability. + { + + + tx.a = tri.b; + tx.b = tri.a; + tx.c = D; + + tx.ab = L1; + tx.ac = T2; + tx.bc = L3; + + + // triangle 2; + tx2.a = tri.b; + tx2.b = tri.c; + tx2.c = D; + + + + tx2.ab = L2; + tx2.ac = t; + tx2.bc = L4; + + + ids2.insert(t); + ids2.insert(T2); + + t2 = tx2; + tri = tx; + + // change knock on triangle labels. + if( L3 >= 0 ) + { + Triad &t3 = triads[L3]; + if( t3.ab == T2 ) t3.ab = t; + else if( t3.bc == T2 ) t3.bc = t; + else if( t3.ac == T2 ) t3.ac = t; + } + + if(L2 >= 0 ) + { + Triad &t4 = triads[L2]; + if( t4.ab == t ) t4.ab = T2; + else if( t4.bc == t ) t4.bc = T2; + else if( t4.ac == t ) t4.ac = T2; + } + + + } + } + } + + + } + + ids.clear(); + ids.insert(ids2.begin(), ids2.end()); + + return(1); +} + diff --git a/src/s_hull/s_hull_pro.h b/src/s_hull/s_hull_pro.h new file mode 100644 index 0000000..68fee00 --- /dev/null +++ b/src/s_hull/s_hull_pro.h @@ -0,0 +1,149 @@ +#ifndef _structures_h +#define _structures_h + + + + +// for FILE + +#include +#include +#include + + + +/* + for use in s_hull_pro.cpp + +S-hull-pro, Copyright (c) 2012 +Dr David SInclair +Cambridge, UK + +email david@s-hull.org + + +*/ + +struct Triad +{ + int a,b, c; + int ab, bc, ac; // adjacent edges index to neighbouring triangle. + float ro, R,C; + //std::set idx; + Triad() {a=b=c=ab=bc=ac=0; ro=R=C=0;}; // added by A.Balakin 6 July 2012 -- uninitialised variable + Triad(int x, int y) : a(x), b(y),c(0), ab(-1), bc(-1), ac(-1), ro(-1), R(0), C(0) {}; + Triad(int x, int y, int z) : a(x), b(y), c(z), ab(-1), bc(-1), ac(-1), ro(-1), R(0), C(0) {}; + Triad(const Triad &p) : a(p.a), b(p.b), c(p.c), ab(p.ab), bc(p.bc), ac(p.ac), ro(p.ro), R(p.R), C(p.C) {}; + + Triad &operator=(const Triad &p) + { + a = p.a; + b = p.b; + c = p.c; + + ab = p.ab; + bc = p.bc; + ac = p.ac; + + ro = p.ro; + R = p.R; + C = p.C; + + return *this; + }; +}; + + + +/* point structure for s_hull only. + has to keep track of triangle ids as hull evolves. +*/ + + +struct Shx +{ + int id, trid; + float r,c, tr,tc ; + float ro; + Shx() {r=c=tr=tc=ro=0; id=trid=0;}; // added by A.Balakin 6 July 2012 -- uninitialised variable + Shx(float a, float b) : r(a), c(b), tr(0.0), tc(0.0), ro(0.0), id(-1) + { trid=0; }; // added by A.Balakin 6 July 2012 -- uninitialised variable + Shx(float a, float b, float x) : r(a), c(b), ro(x), tr(0), tc(0), id(-1) + { trid=0; }; // added by A.Balakin 6 July 2012 -- uninitialised variable + Shx(const Shx &p) : id(p.id), trid(p.trid), r(p.r), c(p.c), tr(p.tr), tc(p.tc), ro(p.ro) {}; + + Shx &operator=(const Shx &p) + { + id = p.id; + trid = p.trid; + r = p.r; + c = p.c; + tr = p.tr; + tc = p.tc; + ro = p.ro; + return *this; + }; + +}; + + +// sort into descending order (for use in corner responce ranking). +inline bool operator<(const Shx &a, const Shx &b) +{ + if( a.ro == b.ro) + return a.r < b.r; + return a.ro < b.ro; +}; + + +struct Dupex +{ + int id; + float r,c; + + Dupex() {}; + Dupex(float a, float b) : id(-1), r(a), c(b) {}; + Dupex(float a, float b, int x) : r(a), c(b), id(x) {}; + Dupex(const Dupex &p) : id(p.id), r(p.r), c(p.c) {}; + + Dupex &operator=(const Dupex &p) + { + id = p.id; + r = p.r; + c = p.c; + return *this; + }; +}; + + + +// sort into descending order (for use in corner responce ranking). +inline bool operator<(const Dupex &a, const Dupex &b) +{ + if( a.r == b.r) + return a.c < b.c; + return a.r < b.r; +}; + + + + + +// from s_hull.C + + +int s_hull_pro( std::vector &pts, std::vector &triads); +void circle_cent2(float r1,float c1, float r2,float c2, float r3,float c3,float &r,float &c, float &ro2); +void circle_cent4(float r1,float c1, float r2,float c2, float r3,float c3,float &r,float &c, float &ro2); +void write_Shx(std::vector &pts, char * fname); +void write_Triads(std::vector &ts, char * fname); +int Cline_Renka_test(float &Ax, float &Ay, float &Bx, float &By, float &Cx, float &Cy, float &Dx, float &Dy); +int T_flip_pro( std::vector &pts, std::vector &triads, std::vector &slump, int numt, int start, std::set &ids); +int T_flip_pro_idx( std::vector &pts, std::vector &triads, std::vector &slump, std::set &ids); + +int read_Shx(std::vector &pts, char * fname); + + +int de_duplicate( std::vector &pts, std::vector &outx ); + +#endif diff --git a/src/surf.cpp b/src/surf.cpp index c4e83a9..37ce385 100644 --- a/src/surf.cpp +++ b/src/surf.cpp @@ -46,12 +46,12 @@ void mgl_surf_plot(mglBase *gr, long *pos, long n, long m) void mgl_fsurf(HMGL gr, const char *eqZ, const char *sch, const char *opt) { // TODO: Add strong function variation analisys ??? if(eqZ==0 || eqZ[0]==0) return; // nothing to plot - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long n = (mgl_isnan(r) || r<=0) ? 100:long(r+0.5); mglData z(n,n); mglFormula *eq = new mglFormula(eqZ); register int i,j; - float dx = (gr->Max.x - gr->Min.x)/(n-1.), dy = (gr->Max.y - gr->Min.y)/(n-1.); + mreal dx = (gr->Max.x - gr->Min.x)/(n-1.), dy = (gr->Max.y - gr->Min.y)/(n-1.); for(j=0;jStop) { delete eq; return; } @@ -64,7 +64,7 @@ void mgl_fsurf(HMGL gr, const char *eqZ, const char *sch, const char *opt) void mgl_fsurf_xyz(HMGL gr, const char *eqX, const char *eqY, const char *eqZ, const char *sch, const char *opt) { // TODO: Add strong function variation analisys ??? if(eqZ==0 || eqZ[0]==0) return; // nothing to plot - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long n = (mgl_isnan(r) || r<=0) ? 100:long(r+0.5); mglData x(n,n), y(n,n), z(n,n); if(n<=0) n=100; @@ -73,7 +73,7 @@ void mgl_fsurf_xyz(HMGL gr, const char *eqX, const char *eqY, const char *eqZ, c ey = new mglFormula(eqY ? eqY : "v"); ez = new mglFormula(eqZ); register int i,j; - register float u,v; + register mreal u,v; for(j=0;jStop) { delete ex; delete ey; delete ez; return; } @@ -110,10 +110,8 @@ void mgl_fsurf_xyz_(uintptr_t *gr, const char *fx, const char *fy, const char *f void mgl_mesh_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Mesh"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Mesh"); return; } - if(y->GetNx()!=m && (x->GetNy()!=m || y->GetNx()!=n || y->GetNy()!=m)) - { gr->SetWarn(mglWarnDim); return; }; + if(mgl_check_dim2(gr,x,y,z,0,"Mesh")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Mesh",cgid++); gr->SetPenPal("-"); @@ -122,7 +120,7 @@ void mgl_mesh_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o gr->Reserve(n*m*z->GetNz()); mglPoint p; - float c; + mreal c; for(k=0;kGetNz();k++) { for(j=0;jGetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Mesh"); return; } gr->SaveState(opt); mglData x(z->GetNx()), y(z->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_mesh_xy(gr,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_mesh_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -163,10 +161,8 @@ void mgl_mesh_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,int void mgl_fall_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=z->GetNx()) { gr->SetWarn(mglWarnDim,"Fall"); return; } - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Fall"); return; } - if(y->GetNx()!=z->GetNy() && (x->GetNy()!=z->GetNy() || y->GetNx()!=z->GetNx() || y->GetNy()!=z->GetNy())) - { gr->SetWarn(mglWarnDim); return; } + if(mgl_check_dim2(gr,x,y,z,0,"Fall")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Fall",cgid++); gr->SetPenPal("-"); @@ -175,7 +171,7 @@ void mgl_fall_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o gr->Reserve(n*m*z->GetNz()); mglPoint p; - float c; + mreal c; for(k=0;kGetNz();k++) { for(j=0;jGetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Fall"); return; } gr->SaveState(opt); mglData x(z->GetNx()), y(z->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_fall_xy(gr,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_fall_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -216,13 +212,11 @@ void mgl_fall_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,int void mgl_grid_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=z->GetNx()) { gr->SetWarn(mglWarnDim,"Grid"); return; } - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Grid"); return; } - if(y->GetNx()!=z->GetNy() && (x->GetNy()!=z->GetNy() || y->GetNx()!=z->GetNx() || y->GetNy()!=z->GetNy())) - { gr->SetWarn(mglWarnDim); return; } + if(mgl_check_dim2(gr,x,y,z,0,"Grid")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Grid",cgid++); - float zVal = gr->Min.z; + mreal zVal = gr->Min.z; gr->SetPenPal(sch?sch:"k-"); long *pos = new long[n*m]; gr->Reserve(n*m*z->GetNz()); @@ -230,7 +224,7 @@ void mgl_grid_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o mglPoint p; for(k=0;kGetNz();k++) { - if(z->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*float(k)/(z->GetNz()-1); + if(z->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(k)/(z->GetNz()-1); for(j=0;jStop) { delete []pos; return; } @@ -244,12 +238,12 @@ void mgl_grid_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o //----------------------------------------------------------------------------- void mgl_grid(HMGL gr, HCDT z,const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Grid"); return; } gr->SaveState(opt); mglData x(z->GetNx()), y(z->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_grid_xy(gr,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_grid_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -269,10 +263,8 @@ void mgl_grid_(uintptr_t *gr, uintptr_t *a,const char *sch, const char *opt,int void mgl_surf_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=n) { gr->SetWarn(mglWarnDim,"Surf"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Surf"); return; } - if(y->GetNx()!=m && (x->GetNy()!=m || y->GetNx()!=n || y->GetNy()!=m)) - { gr->SetWarn(mglWarnDim); return; }; + if(mgl_check_dim2(gr,x,y,z,0,"Surf")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Surf",cgid++); long ss = gr->AddTexture(sch); @@ -281,7 +273,7 @@ void mgl_surf_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o gr->Reserve(n*m*z->GetNz()*(wire?2:1)); mglPoint p,q,s,xx,yy; - float c; + mreal c; for(k=0;kGetNz();k++) { for(j=0;jGetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Surf"); return; } gr->SaveState(opt); mglData x(z->GetNx()), y(z->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_surf_xy(gr,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surf_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -332,20 +324,17 @@ void mgl_surf_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,int void mgl_belt_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=z->GetNx()) { gr->SetWarn(mglWarnDim,"Belt"); return; } - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Belt"); return; } - if(y->GetNx()!=z->GetNy() && (x->GetNy()!=z->GetNy() || y->GetNx()!=z->GetNx() || y->GetNy()!=z->GetNy())) - { gr->SetWarn(mglWarnDim); return; } + if(mgl_check_dim2(gr,x,y,z,0,"Belt")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Belt",cgid++); - long ss = gr->AddTexture(sch); long *pos = new long[2*(n>m?n:m)]; gr->Reserve(2*n*m*z->GetNz()); bool how = !(sch && strchr(sch,'x')); mglPoint p1,p2,q,s,xx,yy; - float c; + mreal c; for(k=0;kGetNz();k++) { if(how) for(i=0;iGetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Belt"); return; } gr->SaveState(opt); mglData x(z->GetNx()), y(z->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_belt_xy(gr,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_belt_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -411,24 +400,22 @@ void mgl_belt_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,int void mgl_dens_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=z->GetNx()) { gr->SetWarn(mglWarnDim,"Dens"); return; } - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Dens"); return; } - if(y->GetNx()!=z->GetNy() && (x->GetNy()!=z->GetNy() || y->GetNx()!=z->GetNx() || y->GetNy()!=z->GetNy())) - { gr->SetWarn(mglWarnDim); return; } + if(mgl_check_dim2(gr,x,y,z,0,"Dens")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Dens",cgid++); - float zVal = gr->Min.z; + mreal zVal = gr->Min.z; long ss = gr->AddTexture(sch); long *pos = new long[n*m]; gr->Reserve(n*m*z->GetNz()); mglPoint p,s=mglPoint(0,0,1); - float zz, c; + mreal zz, c; for(k=0;kGetNz();k++) { if(z->GetNz()>1) - zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*float(k)/(z->GetNz()-1); + zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(k)/(z->GetNz()-1); for(j=0;jStop) { delete []pos; return; } @@ -456,6 +443,7 @@ void mgl_dens(HMGL gr, HCDT z, const char *sch, const char *opt) x.Fill(gr->Min.x, gr->Max.x); y.Fill(gr->Min.y, gr->Max.y); mgl_dens_xy(gr,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_dens_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -495,19 +483,14 @@ void mgl_stfa_(uintptr_t *gr, uintptr_t *re, uintptr_t *im, int *dn, const char void mgl_surfc_xy(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=z->GetNx()) { gr->SetWarn(mglWarnDim,"SurfC"); return; } - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"SurfC"); return; } - if(z->GetNx()*z->GetNy()*z->GetNz()!=c->GetNx()*c->GetNy()*c->GetNz()) - { gr->SetWarn(mglWarnDim); return; } - if(y->GetNx()!=z->GetNy() && (x->GetNy()!=z->GetNy() || y->GetNx()!=z->GetNx() || y->GetNy()!=z->GetNy())) - { gr->SetWarn(mglWarnDim); return; } + if(mgl_check_dim2(gr,x,y,z,c,"SurfC")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("SurfC",cgid++); - long ss = gr->AddTexture(sch); long *pos = new long[n*m]; gr->Reserve(n*m*z->GetNz()); - float col; + mreal col; mglPoint p,q,s,xx,yy; for(k=0;kGetNz();k++) @@ -535,12 +518,12 @@ void mgl_surfc_xy(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, cons //----------------------------------------------------------------------------- void mgl_surfc(HMGL gr, HCDT z, HCDT c, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"SurfC"); return; } gr->SaveState(opt); mglData x(z->GetNx()), y(z->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_surfc_xy(gr,&x,&y,z,c,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surfc_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -561,15 +544,10 @@ void mgl_surfa_xy(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, cons { register long i,j; long k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()!=z->GetNx()) { gr->SetWarn(mglWarnDim,"SurfA"); return; } - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"SurfA"); return; } - if(z->GetNx()*z->GetNy()*z->GetNz()!=c->GetNx()*c->GetNy()*c->GetNz()) - { gr->SetWarn(mglWarnDim); return; } - if(y->GetNx()!=z->GetNy() && (x->GetNy()!=z->GetNy() || y->GetNx()!=z->GetNx() || y->GetNy()!=z->GetNy())) - { gr->SetWarn(mglWarnDim); return; } + if(mgl_check_dim2(gr,x,y,z,c,"SurfA")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("SurfA",cgid++); - long ss = gr->AddTexture(sch); long *pos = new long[n*m]; gr->Reserve(n*m*z->GetNz()); @@ -581,10 +559,10 @@ void mgl_surfa_xy(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, cons { if(gr->Stop) { delete []pos; return; } xx = GetX(x,i,j,k); yy = GetY(y,i,j,k); - p = mglPoint(xx.x, yy.x, z->v(i,j,k)); + mreal vv = z->v(i,j,k); p = mglPoint(xx.x, yy.x, vv); q = mglPoint(xx.y, yy.y, z->dvx(i,j,k)); s = mglPoint(xx.z, yy.z, z->dvy(i,j,k)); - pos[i+n*j] = gr->AddPnt(p,gr->GetC(ss,z->v(i,j,k)),q^s,gr->GetA(c->v(i,j,k))); + pos[i+n*j] = gr->AddPnt(p,gr->GetC(ss,vv),q^s,gr->GetA(c->v(i,j,k))); } mgl_surf_plot(gr,pos,n,m); if(sch && strchr(sch,'#')) @@ -599,12 +577,12 @@ void mgl_surfa_xy(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT c, const char *sch, cons //----------------------------------------------------------------------------- void mgl_surfa(HMGL gr, HCDT z, HCDT c, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"SurfC"); return; } + gr->SaveState(opt); mglData x(z->GetNx()), y(z->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); - gr->SaveState(opt); mgl_surfa_xy(gr,&x,&y,z,c,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surfa_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -624,12 +602,9 @@ void mgl_surfa_(uintptr_t *gr, uintptr_t *z, uintptr_t *a, const char *sch, cons void mgl_boxs_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()GetNx()) { gr->SetWarn(mglWarnDim,"Boxs"); return; } - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Boxs"); return; } - long ly = x->GetNy()>=z->GetNy() ? y->GetNy() : y->GetNx(), lx = x->GetNx(); + if(mgl_check_dim2(gr,x,y,z,0,"Boxs",true)) return; - if(y->GetNx()GetNy() && (x->GetNy()GetNy() || y->GetNx()GetNx() || y->GetNy()GetNy())) - { gr->SetWarn(mglWarnDim); return; } + long ly = x->GetNy()>=m ? y->GetNy() : y->GetNx(), lx = x->GetNx(); gr->SaveState(opt); static int cgid=1; gr->StartGroup("Boxs",cgid++); @@ -639,7 +614,7 @@ void mgl_boxs_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o gr->Reserve(8*n*m*z->GetNz()); mglPoint p1,p2,p3,p4,q,s,t(wire||full?NAN:0,0,1),xx,yy; - float zz,z1,z2,x1,y1,c,z0=gr->GetOrgZ('x'); + mreal zz,z1,z2,x1,y1,c,z0=gr->GetOrgZ('x'); long k1,k2,k3,k4,k5,k6,k7,k8; for(k=0;kGetNz();k++) { @@ -705,12 +680,12 @@ void mgl_boxs_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o //----------------------------------------------------------------------------- void mgl_boxs(HMGL gr, HCDT z, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Boxs"); return; } gr->SaveState(opt); mglData x(z->GetNx()+1), y(z->GetNy()+1); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_boxs_xy(gr,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_boxs_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -730,11 +705,9 @@ void mgl_boxs_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,int void mgl_tile_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()SetWarn(mglWarnDim,"Tile"); return; } - if(n<2 || m<2){ gr->SetWarn(mglWarnLow,"Tile"); return; } - long ly = x->GetNy()>=m ? y->GetNy() : y->GetNx(), lx = x->GetNx(); - if(y->GetNx()GetNy() && (x->GetNy()GetNy() || y->GetNx()GetNx() || y->GetNy()GetNy())) - { gr->SetWarn(mglWarnDim); return; } + if(mgl_check_dim2(gr,x,y,z,0,"Tile",true)) return; + + long ly = x->GetNy()>=z->GetNy() ? y->GetNy() : y->GetNx(), lx = x->GetNx(); gr->SaveState(opt); static int cgid=1; gr->StartGroup("Tile",cgid++); @@ -742,7 +715,7 @@ void mgl_tile_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o gr->Reserve(4*n*m*z->GetNz()); mglPoint p1,p2,p3,p4,s=mglPoint(0,0,1); - float zz,x1,x2,y1,y2,c; + mreal zz,x1,x2,y1,y2,c; long k1,k2,k3,k4; for(k=0;kGetNz();k++) { @@ -766,12 +739,12 @@ void mgl_tile_xy(HMGL gr, HCDT x, HCDT y, HCDT z, const char *sch, const char *o //----------------------------------------------------------------------------- void mgl_tile(HMGL gr, HCDT z, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Tile"); return; } gr->SaveState(opt); mglData x(z->GetNx()+1), y(z->GetNy()+1); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_tile_xy(gr,&x,&y,z,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tile_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -784,15 +757,16 @@ void mgl_tile_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,int char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_tile(_GR_, _DA_(a), s, o); delete []o; delete []s; } //----------------------------------------------------------------------------- +// +// TileS series +// +//----------------------------------------------------------------------------- void mgl_tiles_xy(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT s, const char *sch, const char *opt) { register long i,j,k,n=z->GetNx(),m=z->GetNy(); - if(x->GetNx()GetNx()*s->GetNy()*s->GetNz()!=n*m*z->GetNz()) - { gr->SetWarn(mglWarnDim,"Tile"); return; } - if(n<2 || m<2){ gr->SetWarn(mglWarnLow,"Tile"); return; } + if(mgl_check_dim2(gr,x,y,z,s,"TileS",true)) return; + long ly = x->GetNy()>=z->GetNy() ? y->GetNy() : y->GetNx(), lx = x->GetNx(); - if(y->GetNx()GetNy() && (x->GetNy()GetNy() || y->GetNx()GetNx() || y->GetNy()GetNy())) - { gr->SetWarn(mglWarnDim); return; } gr->SaveState(opt); static int cgid=1; gr->StartGroup("TileS",cgid++); @@ -800,7 +774,7 @@ void mgl_tiles_xy(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT s, const char *sch, cons gr->Reserve(4*n*m*z->GetNz()); mglPoint p1,p2,p3,p4,t=mglPoint(0,0,1); - float zz,x1,x2,x3,x4,y1,y2,y3,y4,ss,sm,c; + mreal zz,x1,x2,x3,x4,y1,y2,y3,y4,ss,sm,c; long k1,k2,k3,k4; for(k=0;kGetNz();k++) { @@ -836,12 +810,12 @@ void mgl_tiles_xy(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT s, const char *sch, cons //----------------------------------------------------------------------------- void mgl_tiles(HMGL gr, HCDT z, HCDT s, const char *sch, const char *opt) { - if(z->GetNx()<2 || z->GetNy()<2){ gr->SetWarn(mglWarnLow,"Tile"); return; } gr->SaveState(opt); mglData x(z->GetNx()+1), y(z->GetNy()+1); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_tiles_xy(gr,&x,&y,z,s,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_tiles_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, uintptr_t *r, const char *sch, const char *opt,int l,int lo) @@ -861,18 +835,16 @@ void mgl_tiles_(uintptr_t *gr, uintptr_t *a, uintptr_t *r, const char *sch, cons void mgl_map_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt) { register long i,j,n=ax->GetNx(),m=ax->GetNy(); - if(n*m!=ay->GetNx()*ay->GetNy()) { gr->SetWarn(mglWarnDim,"Map"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Map"); return; } + if(mgl_check_dim2(gr,x,y,ax,ay,"Map")) return; + bool both = x->GetNx()==n && y->GetNx()==n && x->GetNy()==m && y->GetNy()==m; - if(!(both || (x->GetNx()==n && y->GetNx()==m))) - { gr->SetWarn(mglWarnDim,"Map"); return; } gr->SaveState(opt); static int cgid=1; gr->StartGroup("Map",cgid++); long ss = gr->AddTexture(mgl_have_color(sch)?sch:"rgb",2); long s = both ? n:1, s1, s2; - float xdy,xdx,ydx,ydy,xx,yy; + mreal xdy,xdx,ydx,ydy,xx,yy; mglPoint p,t=mglPoint(NAN); long *pos = new long[n*m]; gr->Reserve(n*m); @@ -899,8 +871,8 @@ void mgl_map_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, cons xx = (x->v(i) - gr->Min.x)/(gr->Max.x - gr->Min.x); yy = (y->v(j) - gr->Min.y)/(gr->Max.y - gr->Min.y); } - if(xx<0) xx=0; if(xx>=1) xx=1/MGL_FLT_EPS; - if(yy<0) yy=0; if(yy>=1) yy=1/MGL_FLT_EPS; + if(xx<0) xx=0; if(xx>=1) xx=1/MGL_EPSILON; + if(yy<0) yy=0; if(yy>=1) yy=1/MGL_EPSILON; pos[i+n*j] = gr->AddPnt(p,gr->GetC(ss,xx,false),t,yy); } if(sch && strchr(sch,'.')) for(i=0;imark_plot(pos[i],'.',-1); @@ -910,12 +882,12 @@ void mgl_map_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, cons //----------------------------------------------------------------------------- void mgl_map(HMGL gr, HCDT ax, HCDT ay, const char *sch, const char *opt) { - if(ax->GetNx()<2 || ax->GetNy()<2) { gr->SetWarn(mglWarnLow,"Map"); return; } gr->SaveState(opt); mglData x(ax->GetNx()), y(ax->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_map_xy(gr,&x,&y,ax,ay,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_map_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) diff --git a/src/vect.cpp b/src/vect.cpp index 6dd2462..a9e6010 100644 --- a/src/vect.cpp +++ b/src/vect.cpp @@ -20,7 +20,6 @@ #include "mgl2/vect.h" #include "mgl2/eval.h" #include "mgl2/data.h" -#include //----------------------------------------------------------------------------- // // Traj series @@ -29,10 +28,10 @@ void mgl_traj_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt) { long m,mx,my,mz,nx,ny,nz,n=ax->GetNx(),pal; - if(n<2) { gr->SetWarn(mglWarnLow,"Traj"); return; } - if(n!=x->GetNx() || z->GetNx()!=n || y->GetNx()!=n || ay->GetNx()!=n || az->GetNx()!=n) - { gr->SetWarn(mglWarnDim,"Traj"); return; } - float len=gr->SaveState(opt); if(mgl_isnan(len)) len = 0; + if(mgl_check_dim1(gr,x,z,y,ax,"Traj")) return; + if(mgl_check_dim1(gr,ax,az,ay,0,"Traj")) return; + + mreal len=gr->SaveState(opt); if(mgl_isnan(len)) len = 0; static int cgid=1; gr->StartGroup("Traj",cgid++); register long i, j; @@ -41,7 +40,7 @@ void mgl_traj_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, co m = x->GetNy()>y->GetNy() ? x->GetNy():y->GetNy(); if(i>m) m=i; if(j>m) m=j; gr->SetPenPal(sch,&pal); gr->Reserve(4*n*m); - float dx,dy,dz,dd,da,xm=0; + mreal dx,dy,dz,dd,da,xm=0; mglPoint p1,p2; for(j=0;jStop) return; nx = jGetNy() ? j:0; ny = jGetNy() ? j:0; nz = jGetNy() ? j:0; mx = jGetNy() ? j:0; my = jGetNy() ? j:0; mz = jGetNy() ? j:0; - da = sqrt(ax->v(i,mx)*ax->v(i,mx)+ay->v(i,my)*ay->v(i,my)+az->v(i,mz)*az->v(i,mz)); + p1 = mglPoint(x->v(i,nx), y->v(i,ny), z->v(i,nz)); + p2 = mglPoint(ax->v(i,mx),ay->v(i,my),az->v(i,mz)); + da = p2.norm(); if(len==0) { if(iv(i+1,nx)-x->v(i,nx); dy=y->v(i+1,ny)-y->v(i,ny); dz=z->v(i+1,nz)-z->v(i,nz); } + { dx=x->v(i+1,nx)-p1.x; dy=y->v(i+1,ny)-p1.y; dz=z->v(i+1,nz)-p1.z; } else - { dx=x->v(i,nx)-x->v(i-1,nx); dy=y->v(i,ny)-y->v(i-1,ny); dz=z->v(i,nz)-z->v(i-1,nz); } + { dx=p1.x-x->v(i-1,nx); dy=p1.y-y->v(i-1,ny); dz=p1.z-z->v(i-1,nz); } dd = da ? 1/da : 0; dd *= sqrt(dx*dx+dy*dy+dz*dz); } else dd = len; - p1 = mglPoint(x->v(i,nx), y->v(i,ny), z->v(i,nz)); - p2 = mglPoint(x->v(i,nx)+dd*ax->v(i,mx), y->v(i,ny)+dd*ay->v(i,my), z->v(i,nz)+dd*az->v(i,mz)); - nx = gr->AddPnt(p1); ny = gr->AddPnt(p2); + nx = gr->AddPnt(p1); ny = gr->AddPnt(p1+dd*p2,-1,mglPoint(NAN),-1,2); gr->vect_plot(nx,ny); } } @@ -80,12 +79,10 @@ void mgl_traj_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, co //----------------------------------------------------------------------------- void mgl_traj_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt) { - if(ax->GetNx()<2) { gr->SetWarn(mglWarnLow,"Traj"); return; } - if(x->GetNx()!=ax->GetNx() || y->GetNx()!=ax->GetNx() || ay->GetNx()!=ax->GetNx()) - { gr->SetWarn(mglWarnDim,"Traj"); return; } gr->SaveState(opt); mglData z(x->GetNx()), az(x->GetNx()); z.Fill(gr->Min.z,gr->Min.z); mgl_traj_xyz(gr,x,y,&z,ax,ay,&az,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_traj_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int l,int lo) @@ -106,10 +103,7 @@ void mgl_traj_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uint void mgl_vect_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt) { long i,j,n=ax->GetNx(),m=ax->GetNy(),k; - if(n*m*ax->GetNz()!=ay->GetNx()*ay->GetNy()*ay->GetNz()) { gr->SetWarn(mglWarnDim,"Vect"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Vect"); return; } - bool both = x->GetNx()==n && y->GetNx()==n && x->GetNy()==m && y->GetNy()==m; - if(!(both || (x->GetNx()==n && y->GetNx()==m))) { gr->SetWarn(mglWarnDim,"Vect"); return; } + if(mgl_check_dim2(gr,x,y,ax,ay,"Vect")) return; gr->SaveState(opt); static int cgid=1; gr->StartGroup("Vect",cgid++); @@ -121,36 +115,38 @@ void mgl_vect_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, con long ss = gr->AddTexture(sch); gr->Reserve(4*n*m); - float zVal = gr->Min.z; + mreal zVal = gr->Min.z; long tx=1,ty=1; if(gr->MeshNum>1) { tx=(n-1)/(gr->MeshNum-1); ty=(m-1)/(gr->MeshNum-1); } if(tx<1) tx=1; if(ty<1) ty=1; - float xm=0,ym,dx,dy; - float dd,dm=(fabs(gr->Max.c)+fabs(gr->Min.c))*1e-5; + mreal xm=0,ym,dx,dy; + mreal dd,dm=(fabs(gr->Max.c)+fabs(gr->Min.c))*1e-5; + mreal vx,vy; for(k=0;kGetNz();k++) for(j=0;jv(i,j,k)*ax->v(i,j,k)+ay->v(i,j,k)*ay->v(i,j,k); - xm = xm>ym ? xm : ym; + vx = ax->v(i,j,k); vy = ay->v(i,j,k); + ym = vx*vx+vy*vy; xm = xm>ym ? xm : ym; } xm = 1./(xm==0 ? 1:sqrt(xm)); long n1,n2; mglPoint p1,p2; - float c1,c2, xx,yy; + mreal c1,c2, xx,yy; for(k=0;kGetNz();k++) { - if(ax->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*float(k)/(ax->GetNz()-1); + if(ax->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(k)/(ax->GetNz()-1); for(i=0;iStop) return; xx = GetX(x,i,j,k).x; yy = GetY(y,i,j,k).x; dx = iv(i,j,k),ay->v(i,j,k)); - dx *= fix ? (dd>dm ? ax->v(i,j,k)/dd : 0) : ax->v(i,j,k)*xm; - dy *= fix ? (dd>dm ? ay->v(i,j,k)/dd : 0) : ay->v(i,j,k)*xm; + vx = ax->v(i,j,k); vy = ay->v(i,j,k); + dx *= tx; dy *= ty; dd = hypot(vx,vy); + dx *= fix ? (dd>dm ? vx/dd : 0) : vx*xm; + dy *= fix ? (dd>dm ? vy/dd : 0) : vy*xm; if(end) { p1 = mglPoint(xx-dx,yy-dy,zVal); p2 = mglPoint(xx,yy,zVal); } else if(beg) { p1 = mglPoint(xx,yy,zVal); p2 = mglPoint(xx+dx,yy+dy,zVal); } @@ -158,6 +154,9 @@ void mgl_vect_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, con if(grd) { c1=gr->GetC(ss,dd*xm-0.5,false); c2=gr->GetC(ss,dd*xm,false);} else c1 = c2 = gr->GetC(ss,dd*xm,false); n1=gr->AddPnt(p1,c1); n2=gr->AddPnt(p2,c2); + // allow vectors outside bounding box + if(n1<0 && n2>=0) n1=gr->AddPnt(p1,c1,mglPoint(NAN),-1,2); + if(n2<0 && n1>=0) n2=gr->AddPnt(p2,c2,mglPoint(NAN),-1,2); if(dot) { gr->line_plot(n1,n2); gr->mark_plot(n1,'.'); } else gr->vect_plot(n1,n2); } @@ -172,6 +171,7 @@ void mgl_vect_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, const char *opt) x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_vect_xy(gr,&x,&y,ax,ay,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_vect_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int l,int lo) @@ -192,12 +192,7 @@ void mgl_vect_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, void mgl_vect_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt) { register long i,j,n=ax->GetNx(),m=ax->GetNy(),l=ax->GetNz(),k; - if(n*m*l!=ay->GetNx()*ay->GetNy()*ay->GetNz() || ax->GetNx()*ax->GetNy()*ax->GetNz()!=az->GetNx()*az->GetNy()*az->GetNz()) - { gr->SetWarn(mglWarnDim,"Vect"); return; } - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Vect"); return; } - bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Vect"); return; } + if(mgl_check_vec3(gr,x,y,z,ax,ay,az,"Vect3")) return; gr->SaveState(opt); static int cgid=1; gr->StartGroup("Vect3",cgid++); @@ -207,24 +202,25 @@ void mgl_vect_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, co bool beg = sch && strchr(sch,'<'); bool grd = sch && strchr(sch,'='); - float xm=0,ym,dx,dy,dz,dd,dm=(fabs(gr->Max.c)+fabs(gr->Min.c))*1e-5; + mreal xm=0,ym,dx,dy,dz,dd,dm=(fabs(gr->Max.c)+fabs(gr->Min.c))*1e-5; long ss = gr->AddTexture(sch); gr->Reserve(2*n*m*l); long tx=1,ty=1,tz=1; if(gr->MeshNum>1) { tx=(n-1)/(gr->MeshNum-1); ty=(m-1)/(gr->MeshNum-1); tz=(l-1)/(gr->MeshNum-1);} if(tx<1) tx=1; if(ty<1) ty=1; if(tz<1) tz=1; + mglPoint p; for(k=0;kv(i,j,k)*ax->v(i,j,k)+ay->v(i,j,k)*ay->v(i,j,k)+az->v(i,j,k)*az->v(i,j,k); - xm = xm>ym ? xm : ym; + p = mglPoint(ax->v(i,j,k),ay->v(i,j,k),az->v(i,j,k)); + ym = p.x*p.x+p.y*p.y+p.z*p.z; xm = xm>ym ? xm : ym; } xm = 1./(xm==0 ? 1:sqrt(xm)); long n1,n2; mglPoint p1,p2; - float c1,c2, xx,yy,zz; + mreal c1,c2, xx,yy,zz; for(k=0;kv(i,j,k)*ax->v(i,j,k)+ay->v(i,j,k)*ay->v(i,j,k)+az->v(i,j,k)*az->v(i,j,k)); - dx *= fix ? (dd>dm ? ax->v(i,j,k)/dd : 0) : ax->v(i,j,k)*xm; - dy *= fix ? (dd>dm ? ay->v(i,j,k)/dd : 0) : ay->v(i,j,k)*xm; - dz *= fix ? (dd>dm ? az->v(i,j,k)/dd : 0) : az->v(i,j,k)*xm; + p = mglPoint(ax->v(i,j,k),ay->v(i,j,k),az->v(i,j,k)); dd = p.norm(); + dx *= fix ? (dd>dm ? p.x/dd : 0) : p.x*xm; + dy *= fix ? (dd>dm ? p.y/dd : 0) : p.y*xm; + dz *= fix ? (dd>dm ? p.z/dd : 0) : p.z*xm; if(end) { p1 = mglPoint(xx-dx,yy-dy,zz-dz); p2 = mglPoint(xx,yy,zz); } else if(beg) { p1 = mglPoint(xx,yy,zz); p2 = mglPoint(xx+dx,yy+dy,zz+dz); } @@ -245,6 +241,9 @@ void mgl_vect_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, co if(grd) { c1=gr->GetC(ss,dd*xm-0.5,false); c2=gr->GetC(ss,dd*xm,false); } else c1 = c2 = gr->GetC(ss,dd*xm,false); n1=gr->AddPnt(p1,c1); n2=gr->AddPnt(p2,c2); + // allow vectors outside bounding box + if(n1<0 && n2>=0) n1=gr->AddPnt(p1,c1,mglPoint(NAN),-1,2); + if(n2<0 && n1>=0) n2=gr->AddPnt(p2,c2,mglPoint(NAN),-1,2); if(dot) { gr->line_plot(n1,n2); gr->mark_plot(n1,'.'); } else gr->vect_plot(n1,n2); } @@ -259,6 +258,7 @@ void mgl_vect_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, const char y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_vect_xyz(gr,&x,&y,&z,ax,ay,az,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_vect_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int l,int lo) @@ -276,16 +276,16 @@ void mgl_vect_3d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, co // Flow 2d series // //----------------------------------------------------------------------------- -void flow(mglBase *gr, float zVal, float u, float v, const mglData &x, const mglData &y, const mglData &ax, const mglData &ay, long ss, bool vv) +void flow(mglBase *gr, mreal zVal, mreal u, mreal v, const mglData &x, const mglData &y, const mglData &ax, const mglData &ay, long ss, bool vv) { long n=10*(ax.nx+ax.ny); bool both = x.nx==ax.nx && y.nx==ax.nx && x.ny==ax.ny && y.ny==ax.ny; mglPoint *pp = new mglPoint[n], dp; - float *cc = new float[n]; + mreal *cc = new mreal[n]; mglPoint dx(1/fabs(gr->Max.x-gr->Min.x),1/fabs(gr->Max.y-gr->Min.y),1/fabs(gr->Max.z-gr->Min.z)); - float dt = 0.5/(ax.nx > ax.ny ? ax.nx : ax.ny),e,f,g,ff[4],gg[4],h,s=1; + mreal dt = 0.5/(ax.nx > ax.ny ? ax.nx : ax.ny),e,f,g,ff[4],gg[4],h,s=1; if(u<0 || v<0) { dt = -dt; u = -u; v = -v; s = -1;} register long k=0,m; bool end = false; @@ -336,26 +336,23 @@ void flow(mglBase *gr, float zVal, float u, float v, const mglData &x, const mgl //----------------------------------------------------------------------------- void mgl_flow_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt) { - float u,v; - long n=ax->GetNx(), m=ax->GetNy(); - if(n*m*ax->GetNz()!=ay->GetNx()*ay->GetNy()*ay->GetNz()) { gr->SetWarn(mglWarnDim,"Flow"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Flow"); return; } - bool both = x->GetNx()==n && y->GetNx()==n && x->GetNy()==m && y->GetNy()==m; - if(!(both || (x->GetNx()==n && y->GetNx()==m))) { gr->SetWarn(mglWarnDim,"Flow"); return; } - float r = gr->SaveState(opt); + mreal u,v; + if(mgl_check_dim2(gr,x,y,ax,ay,"Flow")) return; + + mreal r = gr->SaveState(opt); long num = mgl_isnan(r)?5:long(r+0.5); static int cgid=1; gr->StartGroup("Flow",cgid++); long ss = gr->AddTexture(sch); bool vv = sch && strchr(sch,'v'); // allocate memory - float zVal = gr->Min.z; + mreal zVal = gr->Min.z; bool cnt=!(sch && strchr(sch,'#')); mglData xx(x), yy(y), bx(ax), by(ay); for(long k=0;kGetNz();k++) { - if(ax->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*float(k)/(ax->GetNz()-1); + if(ax->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(k)/(ax->GetNz()-1); for(long i=0;iStop) return; @@ -392,6 +389,7 @@ void mgl_flow_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, const char *opt) x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_flow_xy(gr,&x,&y,ax,ay,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_flow_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt,int l,int lo) @@ -403,15 +401,14 @@ void mgl_flow_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_flow_2d(_GR_, _DA_(ax), _DA_(ay), s, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_flowp_xy(HMGL gr, float x0, float y0, float z0, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt) +void mgl_flowp_xy(HMGL gr, mreal x0, mreal y0, mreal z0, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, const char *opt) { mglPoint p(x0,y0,z0); - float u,v; + mreal u,v; long n=ax->GetNx(), m=ax->GetNy(); - if(n*m*ax->GetNz()!=ay->GetNx()*ay->GetNy()*ay->GetNz()) { gr->SetWarn(mglWarnDim,"Flow"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Flow"); return; } bool both = x->GetNx()==n && y->GetNx()==n && x->GetNy()==m && y->GetNy()==m; - if(!(both || (x->GetNx()==n && y->GetNx()==m))) { gr->SetWarn(mglWarnDim,"Flow"); return; } + if(mgl_check_dim2(gr,x,y,ax,ay,"FlowP")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("FlowP",cgid++); @@ -419,17 +416,17 @@ void mgl_flowp_xy(HMGL gr, float x0, float y0, float z0, HCDT x, HCDT y, HCDT ax bool vv = sch && strchr(sch,'v'); // find coordinates u, v register long i,j; - register float d, dm=1e7; + register mreal d, dm=1e7; long i0=0,j0=0; for(i=0;iv(i,j)-p.x,y->v(i,j)-p.y) : hypot(x->v(i)-p.x,y->v(j)-p.y); if(dv(i0,j0)-p.x; dy = y->v(i0,j0)-p.y; @@ -451,21 +448,22 @@ void mgl_flowp_xy(HMGL gr, float x0, float y0, float z0, HCDT x, HCDT y, HCDT ax gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_flowp_2d(HMGL gr, float x0, float y0, float z0, HCDT ax, HCDT ay, const char *sch, const char *opt) +void mgl_flowp_2d(HMGL gr, mreal x0, mreal y0, mreal z0, HCDT ax, HCDT ay, const char *sch, const char *opt) { gr->SaveState(opt); mglData x(ax->GetNx()), y(ax->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_flowp_xy(gr,x0,y0,z0,&x,&y,ax,ay,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_flowp_xy_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt, int l,int lo) +void mgl_flowp_xy_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt, int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_flowp_xy(_GR_, *x0,*y0,*z0, _DA_(x), _DA_(y), _DA_(ax), _DA_(ay), s, o); delete []o; delete []s; } -void mgl_flowp_2d_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt, int l,int lo) +void mgl_flowp_2d_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0, uintptr_t *ax, uintptr_t *ay, const char *sch, const char *opt, int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_flowp_2d(_GR_, *x0,*y0,*z0, _DA_(ax), _DA_(ay), s, o); delete []o; delete []s; } @@ -474,18 +472,18 @@ void mgl_flowp_2d_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *ax // Flow 3d series // //----------------------------------------------------------------------------- -void flow(mglBase *gr, float u, float v, float w, const mglData &x, const mglData &y, const mglData &z, const mglData &ax, const mglData &ay, const mglData &az,long ss,bool vv, bool xo, bool zo) +void flow(mglBase *gr, mreal u, mreal v, mreal w, const mglData &x, const mglData &y, const mglData &z, const mglData &ax, const mglData &ay, const mglData &az,long ss,bool vv, bool xo, bool zo) { static long n=10*(ax.nx+ax.ny); long nn = ax.nx*ax.ny*ax.nz; bool both = x.nx*x.ny*x.nz==nn && y.nx*y.ny*y.nz==nn && z.nx*z.ny*z.nz==nn; mglPoint *pp = new mglPoint[n], dp; - float *cc = new float[n]; + mreal *cc = new mreal[n]; mglPoint dx(1/fabs(gr->Max.x-gr->Min.x),1/fabs(gr->Max.y-gr->Min.y),1/fabs(gr->Max.z-gr->Min.z)); nn = (ax.nx > ax.ny ? ax.nx : ax.ny); nn = (nn > ax.nz ? nn : ax.nz); - float dt = 0.2/nn, e,f,g,ee[4],ff[4],gg[4],h,s=1,u1,v1,w1; + mreal dt = 0.2/nn, e,f,g,ee[4],ff[4],gg[4],h,s=1,u1,v1,w1; if(u<0 || v<0 || w<0) { dt = -dt; u = -u; v = -v; w = -w; s = -1;} register long k=0,m; @@ -524,7 +522,7 @@ void flow(mglBase *gr, float u, float v, float w, const mglData &x, const mglDat if(k>1) { long i,j,jj,a=long(1./fabs(dt)); - float rr = mgl_norm(gr->Max-gr->Min)*gr->BarWidth/25, ll; + mreal rr = mgl_norm(gr->Max-gr->Min)*gr->BarWidth/25, ll; mglPoint q1,q2,l; long n1=-1,n2=-1,n3=-1,n4=-1, m1=-1,m2=-1,m3=-1,m4=-1; @@ -558,16 +556,11 @@ void flow(mglBase *gr, float u, float v, float w, const mglData &x, const mglDat //----------------------------------------------------------------------------- void mgl_flow_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt) { - float u,v,w; - long i,j,n=ax->GetNx(),m=ax->GetNy(),l=ax->GetNz(); - if(ax->GetNx()*ax->GetNy()*ax->GetNz()!=ay->GetNx()*ay->GetNy()*ay->GetNz() || ax->GetNx()*ax->GetNy()*ax->GetNz()!=az->GetNx()*az->GetNy()*az->GetNz()) - { gr->SetWarn(mglWarnDim,"Flow"); return; } - if(ax->GetNx()<2 || ax->GetNy()<2 || ax->GetNz()<2) - { gr->SetWarn(mglWarnLow,"Flow"); return; } - bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Flow"); return; } - float r = gr->SaveState(opt); + mreal u,v,w; + long i,j; + if(mgl_check_vec3(gr,x,y,z,ax,ay,az,"Flow3")) return; + + mreal r = gr->SaveState(opt); long num = mgl_isnan(r)?3:long(r+0.5); static int cgid=1; gr->StartGroup("Flow3",cgid++); bool cnt=!(sch && strchr(sch,'#')); @@ -620,6 +613,7 @@ void mgl_flow_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, const char y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_flow_xyz(gr,&x,&y,&z,ax,ay,az,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_flow_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt,int l,int lo) @@ -631,18 +625,14 @@ void mgl_flow_3d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, co char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_flow_3d(_GR_, _DA_(ax), _DA_(ay), _DA_(az), s, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_flowp_xyz(HMGL gr, float x0, float y0, float z0, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt) +void mgl_flowp_xyz(HMGL gr, mreal x0, mreal y0, mreal z0, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt) { mglPoint p(x0,y0,z0); - float u,v,w; + mreal u,v,w; long n=ax->GetNx(),m=ax->GetNy(),l=ax->GetNz(); - if(ax->GetNx()*ax->GetNy()*ax->GetNz()!=ay->GetNx()*ay->GetNy()*ay->GetNz() || ax->GetNx()*ax->GetNy()*ax->GetNz()!=az->GetNx()*az->GetNy()*az->GetNz()) - { gr->SetWarn(mglWarnDim,"Flow"); return; } - if(ax->GetNx()<2 || ax->GetNy()<2 || ax->GetNz()<2) - { gr->SetWarn(mglWarnLow,"Flow"); return; } bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Flow"); return; } + if(mgl_check_vec3(gr,x,y,z,ax,ay,az,"FlowP3")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("FlowP3",cgid++); long ss = gr->AddTexture(sch); @@ -650,9 +640,9 @@ void mgl_flowp_xyz(HMGL gr, float x0, float y0, float z0, HCDT x, HCDT y, HCDT z // find coordinates u, v, w register long i,j,k; - register float d, dm=1e7; + register mreal d, dm=1e7; long i0=0,j0=0,k0=0; - float dx,dy,dz; + mreal dx,dy,dz; for(i=0;iv(i0,j0,k0)-p.x; dy = y->v(i0,j0,k0)-p.y; dz = z->v(i0,j0,k0)-p.z; @@ -690,7 +680,7 @@ void mgl_flowp_xyz(HMGL gr, float x0, float y0, float z0, HCDT x, HCDT y, HCDT z gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_flowp_3d(HMGL gr, float x0, float y0, float z0, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt) +void mgl_flowp_3d(HMGL gr, mreal x0, mreal y0, mreal z0, HCDT ax, HCDT ay, HCDT az, const char *sch, const char *opt) { gr->SaveState(opt); mglData x(ax->GetNx()), y(ax->GetNy()), z(ax->GetNz()); @@ -698,14 +688,15 @@ void mgl_flowp_3d(HMGL gr, float x0, float y0, float z0, HCDT ax, HCDT ay, HCDT y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_flowp_xyz(gr, x0,y0,z0, &x,&y,&z,ax,ay,az,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_flowp_xyz_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt, int l,int lo) +void mgl_flowp_xyz_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt, int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_flowp_xyz(_GR_, *x0,*y0,*z0, _DA_(x), _DA_(y), _DA_(z), _DA_(ax), _DA_(ay), _DA_(az), s, o); delete []o; delete []s; } -void mgl_flowp_3d_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt, int l,int lo) +void mgl_flowp_3d_(uintptr_t *gr, mreal *x0, mreal *y0, mreal *z0, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, const char *opt, int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_flowp_3d(_GR_, *x0,*y0,*z0, _DA_(ax), _DA_(ay), _DA_(az), s, o); delete []o; delete []s; } @@ -716,7 +707,8 @@ void mgl_flowp_3d_(uintptr_t *gr, float *x0, float *y0, float *z0, uintptr_t *ax //----------------------------------------------------------------------------- void mgl_grad_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT phi, const char *sch, const char *opt) { - mglData ax(phi), ay(phi),az(phi),xx(phi),yy(phi),zz(phi); + mglData ax(phi), ay,az,xx,yy,zz; + ay.Set(ax); az.Set(ax); xx.Set(ax); yy.Set(ax); zz.Set(ax); long n=xx.nx, m=xx.ny, l=xx.nz, nn = n*m*l; if(x->GetNx()*x->GetNy()*x->GetNz()==nn && y->GetNx()*y->GetNy()*y->GetNz()==nn && x->GetNx()*x->GetNy()*x->GetNz()==nn) { xx.Set(x); yy.Set(y); zz.Set(z); } // nothing to do @@ -734,7 +726,8 @@ void mgl_grad_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT phi, const char *sch, co //----------------------------------------------------------------------------- void mgl_grad_xy(HMGL gr, HCDT x, HCDT y, HCDT phi, const char *sch, const char *opt) { - mglData ax(phi), ay(phi),xx(phi),yy(phi); + mglData ax(phi), ay,xx,yy; + ay.Set(ax); xx.Set(ax); yy.Set(ax); long n = phi->GetNx(), m=phi->GetNy(), nn=n*m; if(x->GetNx()*x->GetNy()==nn && y->GetNx()*y->GetNy()==nn) { xx.Set(x); yy.Set(y); } else if(x->GetNx()==n && y->GetNx()==m) @@ -755,6 +748,7 @@ void mgl_grad(HMGL gr, HCDT phi, const char *sch, const char *opt) x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); if(phi->GetNz()==1) mgl_grad_xy(gr,&x,&y,phi,sch,0); else mgl_grad_xyz(gr,&x,&y,&z,phi,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_grad_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ph, const char *sch, const char *opt, int l,int lo) @@ -776,17 +770,17 @@ void mgl_grad_(uintptr_t *gr, uintptr_t *ph, const char *sch, const char *opt, i // Pipe 2d series // //----------------------------------------------------------------------------- -void flowr(mglBase *gr, float zVal, float u, float v, const mglData &x, const mglData &y, const mglData &ax, const mglData &ay, float r0,long sc) +void flowr(mglBase *gr, mreal zVal, mreal u, mreal v, const mglData &x, const mglData &y, const mglData &ax, const mglData &ay, mreal r0,long sc) { long n=10*(ax.nx+ax.ny); bool both = x.nx==ax.nx && y.nx==ax.nx && x.ny==ax.ny && y.ny==ax.ny; mglPoint *pp = new mglPoint[n], dp; - float *cc = new float[n]; + mreal *cc = new mreal[n]; mglPoint dx(1/fabs(gr->Max.x-gr->Min.x),1/fabs(gr->Max.y-gr->Min.y),1/fabs(gr->Max.z-gr->Min.z)); - float dt = 0.5/(ax.nx > ax.ny ? ax.nx : ax.ny),e,f,g,ff[4],gg[4],h,s=1; - float ss = 4./mgl_ipow(gr->Max.c - gr->Min.c,2); + mreal dt = 0.5/(ax.nx > ax.ny ? ax.nx : ax.ny),e,f,g,ff[4],gg[4],h,s=1; + mreal ss = 4./mgl_ipow(gr->Max.c - gr->Min.c,2); if(u<0 || v<0) { dt = -dt; u = -u; v = -v; s = -1;} register long k=0,m; bool end = false; @@ -824,7 +818,7 @@ void flowr(mglBase *gr, float zVal, float u, float v, const mglData &x, const mg long i,j,*id=new long[2*num]; mglPoint p,l=pp[1]-pp[0],t,q,d; t = !l; t.Normalize(); q = t^l; q.Normalize(); - float si,co,fi, rr=pp[0].c,dr=l.c; + mreal si,co,fi, rr=pp[0].c,dr=l.c; gr->Reserve(num*k); for(j=0;jGetNx(), m=ax->GetNy(); - if(n*m*ax->GetNz()!=ay->GetNx()*ay->GetNy()*ay->GetNz()) { gr->SetWarn(mglWarnDim,"Pipe"); return; } - if(n<2 || m<2) { gr->SetWarn(mglWarnLow,"Pipe"); return; } - bool both = x->GetNx()==n && y->GetNx()==n && x->GetNy()==m && y->GetNy()==m; - if(!(both || (x->GetNx()==n && y->GetNx()==m))) { gr->SetWarn(mglWarnDim,"Pipe"); return; } - float r = gr->SaveState(opt); + mreal u,v; + if(mgl_check_dim2(gr,x,y,ax,ay,"Pipe")) return; + + mreal r = gr->SaveState(opt); long num = mgl_isnan(r)?5:long(r+0.5); static int cgid=1; gr->StartGroup("Pipe",cgid++); long ss = gr->AddTexture(sch); // allocate memory - float zVal = gr->Min.z; + mreal zVal = gr->Min.z; bool cnt=!(sch && strchr(sch,'#')); if(sch && strchr(sch,'i')) r0 = -fabs(r0); mglData xx(x), yy(y), bx(ax), by(ay); for(long k=0;kGetNz();k++) { - if(ax->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*float(k)/(ax->GetNz()-1); + if(ax->GetNz()>1) zVal = gr->Min.z+(gr->Max.z-gr->Min.z)*mreal(k)/(ax->GetNz()-1); for(long i=0;iStop) return; @@ -906,20 +897,21 @@ void mgl_pipe_xy(HMGL gr, HCDT x, HCDT y, HCDT ax, HCDT ay, const char *sch, flo gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_pipe_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, float r0, const char *opt) +void mgl_pipe_2d(HMGL gr, HCDT ax, HCDT ay, const char *sch, mreal r0, const char *opt) { gr->SaveState(opt); mglData x(ax->GetNx()), y(ax->GetNy()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); mgl_pipe_xy(gr,&x,&y,ax,ay,sch,r0,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_pipe_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, float *r0, const char *opt,int l,int lo) +void mgl_pipe_xy_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *ax, uintptr_t *ay, const char *sch, mreal *r0, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_pipe_xy(_GR_, _DA_(x), _DA_(y), _DA_(ax), _DA_(ay), s, *r0, o); delete []o; delete []s; } -void mgl_pipe_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, float *r0, const char *opt,int l,int lo) +void mgl_pipe_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, mreal *r0, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_pipe_2d(_GR_, _DA_(ax), _DA_(ay), s, *r0, o); delete []o; delete []s; } @@ -928,19 +920,19 @@ void mgl_pipe_2d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, const char *sch, // Pipe 3d series // //----------------------------------------------------------------------------- -void flowr(mglBase *gr, float u, float v, float w, const mglData &x, const mglData &y, const mglData &z, const mglData &ax, const mglData &ay, const mglData &az, float r0,long sc) +void flowr(mglBase *gr, mreal u, mreal v, mreal w, const mglData &x, const mglData &y, const mglData &z, const mglData &ax, const mglData &ay, const mglData &az, mreal r0,long sc) { static long n=10*(ax.nx+ax.ny); long nn = ax.nx*ax.ny*ax.nz; bool both = x.nx*x.ny*x.nz==nn && y.nx*y.ny*y.nz==nn && z.nx*z.ny*z.nz==nn; mglPoint *pp = new mglPoint[n], dp; - float *cc = new float[n]; + mreal *cc = new mreal[n]; mglPoint dx(1/fabs(gr->Max.x-gr->Min.x),1/fabs(gr->Max.y-gr->Min.y),1/fabs(gr->Max.z-gr->Min.z)); nn = (ax.nx > ax.ny ? ax.nx : ax.ny); nn = (nn > ax.nz ? nn : ax.nz); - float dt = 0.2/nn, e,f,g,ee[4],ff[4],gg[4],h,s=1,u1,v1,w1; - float ss = 4./mgl_ipow(gr->Max.c - gr->Min.c,2); + mreal dt = 0.2/nn, e,f,g,ee[4],ff[4],gg[4],h,s=1,u1,v1,w1; + mreal ss = 4./mgl_ipow(gr->Max.c - gr->Min.c,2); if(u<0 || v<0 || w<0) { dt = -dt; u = -u; v = -v; w = -w; s = -1;} @@ -984,7 +976,7 @@ void flowr(mglBase *gr, float u, float v, float w, const mglData &x, const mglDa long i,j,*id=new long[2*num]; mglPoint p,l=pp[1]-pp[0],t,q,d; t = !l; t.Normalize(); q = t^l; q.Normalize(); - float si,co,fi, rr=pp[0].c,dr=l.c; + mreal si,co,fi, rr=pp[0].c,dr=l.c; gr->Reserve(num*k); for(j=0;jGetNx(),m=ax->GetNy(),l=ax->GetNz(); - if(ax->GetNx()*ax->GetNy()*ax->GetNz()!=ay->GetNx()*ay->GetNy()*ay->GetNz() || ax->GetNx()*ax->GetNy()*ax->GetNz()!=az->GetNx()*az->GetNy()*az->GetNz()) - { gr->SetWarn(mglWarnDim,"Pipe"); return; } - if(ax->GetNx()<2 || ax->GetNy()<2 || ax->GetNz()<2) - { gr->SetWarn(mglWarnLow,"Pipe"); return; } - bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Pipe"); return; } - float r = gr->SaveState(opt); + mreal u,v,w; + long i,j; + if(mgl_check_vec3(gr,x,y,z,ax,ay,az,"Vect")) return; + + mreal r = gr->SaveState(opt); long num = mgl_isnan(r)?3:long(r+0.5); static int cgid=1; gr->StartGroup("Pipe3",cgid++); if(sch && strchr(sch,'i')) r0 = -fabs(r0); @@ -1072,7 +1059,7 @@ void mgl_pipe_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT ax, HCDT ay, HCDT az, co gr->EndGroup(); } //----------------------------------------------------------------------------- -void mgl_pipe_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, float r0, const char *opt) +void mgl_pipe_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, mreal r0, const char *opt) { gr->SaveState(opt); mglData x(ax->GetNx()), y(ax->GetNy()), z(ax->GetNz()); @@ -1080,14 +1067,15 @@ void mgl_pipe_3d(HMGL gr, HCDT ax, HCDT ay, HCDT az, const char *sch, float r0, y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_pipe_xyz(gr,&x,&y,&z,ax,ay,az,sch,r0,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_pipe_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, float *r0, const char *opt,int l,int lo) +void mgl_pipe_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, mreal *r0, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_pipe_xyz(_GR_, _DA_(x), _DA_(y), _DA_(z), _DA_(ax), _DA_(ay), _DA_(az), s, *r0, o); delete []o; delete []s; } -void mgl_pipe_3d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, float *r0, const char *opt,int l,int lo) +void mgl_pipe_3d_(uintptr_t *gr, uintptr_t *ax, uintptr_t *ay, uintptr_t *az, const char *sch, mreal *r0, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_pipe_3d(_GR_, _DA_(ax), _DA_(ay), _DA_(az), s, *r0, o); delete []o; delete []s; } diff --git a/src/volume.cpp b/src/volume.cpp index 2533ff5..7c40043 100644 --- a/src/volume.cpp +++ b/src/volume.cpp @@ -31,24 +31,23 @@ void mgl_cloud_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, con { if(!(gr->GetQuality()&3)) return; // do nothing in fast_draw long i,j,k,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); - register int i0; - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Cloud"); return; } - bool both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim); return; } + register long i0; + bool both = mgl_isboth(x,y,z,a); + if(mgl_check_dim3(gr,both,x,y,z,a,0,"Cloud")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Cloud",cgid++); - int tx=1,ty=1,tz=1; + long tx=1,ty=1,tz=1; if(gr->MeshNum>1) { tx=(n-1)/(gr->MeshNum-1); ty=(m-1)/(gr->MeshNum-1); tz=(l-1)/(gr->MeshNum-1);} if(tx<1) tx=1; if(ty<1) ty=1; if(tz<1) tz=1; - float alpha = gr->AlphaDef; + mreal alpha = gr->AlphaDef; bool inv = sch && strchr(sch,'!'); bool dot = sch && strchr(sch,'.'); alpha /= pow(n/tx*m/ty*l/tz,1./3)/20; - float aa,bb; + mreal aa,bb; if(alpha>1) alpha = 1; long ss = gr->AddTexture(sch); @@ -79,14 +78,13 @@ void mgl_cloud_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, con //----------------------------------------------------------------------------- void mgl_cloud(HMGL gr, HCDT a, const char *sch, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2 || a->GetNz()<2) - { gr->SetWarn(mglWarnLow,"Cloud"); return; } gr->SaveState(opt); mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_cloud_xyz(gr,&x,&y,&z,a,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_cloud_xyz_(uintptr_t *gr, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, const char *opt,int l,int lo) @@ -103,11 +101,11 @@ void mgl_cloud_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,in // Surf3 series // //----------------------------------------------------------------------------- -mglPoint mgl_normal_3d(const mglDataA *a, mglPoint p, bool inv, long n,long m,long l) +mglPoint mgl_normal_3d(HCDT a, mglPoint p, bool inv, long n,long m,long l) { register long i,j,k; - register float x=p.x, y=p.y, z=p.z; - float nx=0, ny=0, nz=0; + register mreal x=p.x, y=p.y, z=p.z; + mreal nx=0, ny=0, nz=0; i=long(x); j=long(y); k=long(z); i = idvx(i); + mreal nx = a->dvx(i); if(idvx(i+1)*x; return inv ? nx : -nx; } @@ -147,10 +145,10 @@ mglPoint mgl_find_norm(bool both, HCDT x, HCDT y, HCDT z, HCDT a, mglPoint u, bo return q; } //----------------------------------------------------------------------------- -inline float mgl_cos_pp(const mglPoint *kk,long i0,long i1,long i2) +inline mreal mgl_cos_pp(const mglPoint *kk,long i0,long i1,long i2) { mglPoint dp1 = kk[i1]-kk[i0], dp2 = kk[i2]-kk[i0]; - float p1=dp1*dp1,p2=dp2*dp2,pc=dp1*dp2; + mreal p1=dp1*dp1,p2=dp2*dp2,pc=dp1*dp2; return p1*p2>1e-10 ? pc/sqrt(p1*p2) : NAN; } //----------------------------------------------------------------------------- @@ -159,7 +157,7 @@ void mgl_surf3_plot(HMGL gr, long n,long m,long *kx1,long *kx2,long *ky1,long *k register long i,j,k,i0,ii,jj; long id[12],us[12],pd[12],ni; mglPoint pp[12]; - float d,d0; + mreal d,d0; for(i=0;iGetNx(),m=a->GetNy(),l=a->GetNz(); long *kx1,*kx2,*ky1,*ky2,*kz; - bool both, wire = sch && strchr(sch,'#'); - float d; - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Surf3"); return; } - both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Surf3"); return; } + bool both = mgl_isboth(x,y,z,a), wire = sch && strchr(sch,'#'); + mreal d; + if(mgl_check_dim3(gr,both,x,y,z,a,0,"Surf3")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Surf3",cgid++); @@ -247,12 +243,12 @@ void mgl_surf3_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, const kx1 = new long[n*m]; kx2 = new long[n*m]; ky1 = new long[n*m]; ky2 = new long[n*m]; kz = new long[n*m]; - float c=gr->GetC(ss,val); + mreal c=gr->GetC(ss,val); std::vector kk; kk.reserve(n*m*l); - mglPoint p,q,u; - float a0; + mglPoint p,q,u, p0; + mreal a0; for(k=0;kStop) { delete []kx1; delete []kx2; delete []ky1; delete []ky2; delete []kz; return; } i1 = i+n*j; a0 = a->v(i,j,k); + p0 = both?mglPoint(x->v(i,j,k), y->v(i,j,k), z->v(i,j,k)) : mglPoint(x->v(i), y->v(j), z->v(k)); if(iv(i+1,j,k)); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k)*(1-d)+x->v(i+1,j,k)*d, - y->v(i,j,k)*(1-d)+y->v(i+1,j,k)*d, - z->v(i,j,k)*(1-d)+z->v(i+1,j,k)*d); - else p = mglPoint(x->v(i)*(1-d)+x->v(i+1)*d, y->v(j), z->v(k)); + if(both) p = mglPoint(p0.x*(1-d)+x->v(i+1,j,k)*d, + p0.y*(1-d)+y->v(i+1,j,k)*d, + p0.z*(1-d)+z->v(i+1,j,k)*d); + else p = mglPoint(p0.x*(1-d)+x->v(i+1)*d, p0.y, p0.z); u = mglPoint(i+d,j,k); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); pos = gr->AddPnt(p,c,q); u.c=pos; @@ -285,10 +282,10 @@ void mgl_surf3_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, const d = mgl_d(val,a0,a->v(i,j+1,k)); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k)*(1-d)+x->v(i,j+1,k)*d, - y->v(i,j,k)*(1-d)+y->v(i,j+1,k)*d, - z->v(i,j,k)*(1-d)+z->v(i,j+1,k)*d); - else p = mglPoint(x->v(i), y->v(j)*(1-d)+y->v(j+1)*d, z->v(k)); + if(both) p = mglPoint(p0.x*(1-d)+x->v(i,j+1,k)*d, + p0.y*(1-d)+y->v(i,j+1,k)*d, + p0.z*(1-d)+z->v(i,j+1,k)*d); + else p = mglPoint(p0.x, p0.y*(1-d)+y->v(j+1)*d, p0.z); u = mglPoint(i,j+d,k); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); pos = gr->AddPnt(p,c,q); u.c=pos; @@ -301,10 +298,10 @@ void mgl_surf3_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, const d = mgl_d(val,a->v(i,j,k-1),a0); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k-1)*(1-d)+x->v(i,j,k)*d, - y->v(i,j,k-1)*(1-d)+y->v(i,j,k)*d, - z->v(i,j,k-1)*(1-d)+z->v(i,j,k)*d); - else p = mglPoint(x->v(i), y->v(j), z->v(k-1)*(1-d)+z->v(k)*d); + if(both) p = mglPoint(x->v(i,j,k-1)*(1-d)+p0.x*d, + y->v(i,j,k-1)*(1-d)+p0.y*d, + z->v(i,j,k-1)*(1-d)+p0.z*d); + else p = mglPoint(p0.x, p0.y, z->v(k-1)*(1-d)+p0.z*d); u = mglPoint(i,j,k+d-1); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); pos = gr->AddPnt(p,c,q); u.c=pos; @@ -320,45 +317,46 @@ void mgl_surf3_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, const delete []ky2; delete []kz; } //----------------------------------------------------------------------------- -void mgl_surf3_val(HMGL gr, float val, HCDT a, const char *sch, const char *opt) +void mgl_surf3_val(HMGL gr, mreal val, HCDT a, const char *sch, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2 || a->GetNz()<2) { gr->SetWarn(mglWarnLow,"Surf3"); return; } gr->SaveState(opt); - mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); + mglData x(a->GetNx()), y(a->GetNy()), z(a->GetNz()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_surf3_xyz_val(gr,val,&x,&y,&z,a,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surf3_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long num = mgl_isnan(r)?3:long(r+0.5); for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); + mreal v = gr->Max.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); mgl_surf3_xyz_val(gr,v,x,y,z,a,sch,0); } + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surf3(HMGL gr, HCDT a, const char *sch, const char *opt) { - float r = gr->SaveState(opt); - long num = mgl_isnan(r)?3:long(r+0.5); - for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); - mgl_surf3_val(gr,v,a,sch,0); - } + gr->SaveState(opt); + mglData x(a->GetNx()), y(a->GetNy()), z(a->GetNz()); + x.Fill(gr->Min.x,gr->Max.x); + y.Fill(gr->Min.y,gr->Max.y); + z.Fill(gr->Min.z,gr->Max.z); + mgl_surf3_xyz(gr,&x,&y,&z,a,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_surf3_xyz_val_(uintptr_t *gr, float *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, const char *opt,int l,int lo) +void mgl_surf3_xyz_val_(uintptr_t *gr, mreal *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, const char *sch, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_surf3_xyz_val(_GR_, *Val, _DA_(x), _DA_(y), _DA_(z), _DA_(a), s, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_surf3_val_(uintptr_t *gr, float *Val, uintptr_t *a, const char *sch, const char *opt,int l,int lo) +void mgl_surf3_val_(uintptr_t *gr, mreal *Val, uintptr_t *a, const char *sch, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_surf3_val(_GR_, *Val, _DA_(a), s, o); delete []o; delete []s; } @@ -377,17 +375,14 @@ void mgl_surf3_(uintptr_t *gr, uintptr_t *a, const char *sch, const char *opt,in // Surf3A series // //----------------------------------------------------------------------------- -void mgl_surf3a_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *sch, const char *opt) +void mgl_surf3a_xyz_val(HMGL gr, mreal val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *sch, const char *opt) { long i,j,k,i1,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); long *kx1,*kx2,*ky1,*ky2,*kz; - bool both, wire = sch && strchr(sch,'#'); - float d; - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Surf3A"); return; } - both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Surf3A"); return; } - if(b->GetNx()*b->GetNy()*b->GetNz()!=n*m*l) { gr->SetWarn(mglWarnDim,"Surf3A"); return; } + bool both = mgl_isboth(x,y,z,a), wire = sch && strchr(sch,'#'); + mreal d; + if(mgl_check_dim3(gr,both,x,y,z,a,b,"Surf3A")) return; + gr->SaveState(opt); static int cgid=1; gr->StartGroup("Surf3A",cgid++); @@ -397,12 +392,12 @@ void mgl_surf3a_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT kx1 = new long[n*m]; kx2 = new long[n*m]; ky1 = new long[n*m]; ky2 = new long[n*m]; kz = new long[n*m]; - float c=gr->GetC(ss,val),aa; + mreal c=gr->GetC(ss,val),aa; std::vector kk; kk.reserve(n*m*l); - mglPoint p,q,u; - float a0,b0; + mglPoint p,q,u, p0; + mreal a0,b0; for(k=0;kv(i,j,k); b0 = b->v(i,j,k); + p0 = both?mglPoint(x->v(i,j,k), y->v(i,j,k), z->v(i,j,k)) : mglPoint(x->v(i), y->v(j), z->v(k)); if(iv(i+1,j,k)); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k)*(1-d)+x->v(i+1,j,k)*d, - y->v(i,j,k)*(1-d)+y->v(i+1,j,k)*d, - z->v(i,j,k)*(1-d)+z->v(i+1,j,k)*d); - else p = mglPoint(x->v(i)*(1-d)+x->v(i+1)*d, y->v(j), z->v(k)); + if(both) p = mglPoint(p0.x*(1-d)+x->v(i+1,j,k)*d, + p0.y*(1-d)+y->v(i+1,j,k)*d, + p0.z*(1-d)+z->v(i+1,j,k)*d); + else p = mglPoint(p0.x*(1-d)+x->v(i+1)*d, p0.y, p0.z); aa = gr->GetA(b0*(1-d)+b->v(i+1,j,k)*d); u = mglPoint(i+d,j,k); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); @@ -437,10 +433,10 @@ void mgl_surf3a_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT d = mgl_d(val,a0,a->v(i,j+1,k)); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k)*(1-d)+x->v(i,j+1,k)*d, - y->v(i,j,k)*(1-d)+y->v(i,j+1,k)*d, - z->v(i,j,k)*(1-d)+z->v(i,j+1,k)*d); - else p = mglPoint(x->v(i), y->v(j)*(1-d)+y->v(j+1)*d, z->v(k)); + if(both) p = mglPoint(p0.x*(1-d)+x->v(i,j+1,k)*d, + p0.y*(1-d)+y->v(i,j+1,k)*d, + p0.z*(1-d)+z->v(i,j+1,k)*d); + else p = mglPoint(p0.x, p0.y*(1-d)+y->v(j+1)*d, p0.z); aa = gr->GetA(b0*(1-d)+b->v(i,j+1,k)*d); u = mglPoint(i,j+d,k); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); @@ -454,10 +450,10 @@ void mgl_surf3a_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT d = mgl_d(val,a->v(i,j,k-1),a0); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k-1)*(1-d)+x->v(i,j,k)*d, - y->v(i,j,k-1)*(1-d)+y->v(i,j,k)*d, - z->v(i,j,k-1)*(1-d)+z->v(i,j,k)*d); - else p = mglPoint(x->v(i), y->v(j), z->v(k-1)*(1-d)+z->v(k)*d); + if(both) p = mglPoint(x->v(i,j,k-1)*(1-d)+p0.x*d, + y->v(i,j,k-1)*(1-d)+p0.y*d, + z->v(i,j,k-1)*(1-d)+p0.z*d); + else p = mglPoint(p0.x, p0.y, z->v(k-1)*(1-d)+p0.z*d); aa = gr->GetA(b->v(i,j,k-1)*(1-d)+b0*d); u = mglPoint(i,j,k+d-1); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); @@ -474,25 +470,24 @@ void mgl_surf3a_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT delete []ky2; delete []kz; } //----------------------------------------------------------------------------- -void mgl_surf3a_val(HMGL gr, float val, HCDT a, HCDT b, const char *sch, const char *opt) +void mgl_surf3a_val(HMGL gr, mreal val, HCDT a, HCDT b, const char *sch, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2 || a->GetNz()<2) - { gr->SetWarn(mglWarnLow,"Surf3A"); return; } gr->SaveState(opt); mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_surf3a_xyz_val(gr,val,&x,&y,&z,a,b,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surf3a_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long num = mgl_isnan(r)?3:long(r+0.5); if(b->GetNx()==num && b->GetNy()==1 && b->GetNz()==1) { - float v,a0=gr->AlphaDef; + mreal v,a0=gr->AlphaDef; for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); @@ -503,40 +498,30 @@ void mgl_surf3a_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char } else for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); + mreal v = gr->Max.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); mgl_surf3a_xyz_val(gr,v,x,y,z,a,b,sch,0); } + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surf3a(HMGL gr, HCDT a, HCDT b, const char *sch, const char *opt) { - float r = gr->SaveState(opt); - long num = mgl_isnan(r)?3:long(r); - if(b->GetNx()==num && b->GetNy()==1 && b->GetNz()==1) - { - float v,a0=gr->AlphaDef; - for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); - gr->AlphaDef = b->v(i); - mgl_surf3_val(gr,v,a,sch,0); - } - gr->AlphaDef = a0; - } - else for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); - mgl_surf3a_val(gr,v,a,b,sch,0); - } + gr->SaveState(opt); + mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); + x.Fill(gr->Min.x,gr->Max.x); + y.Fill(gr->Min.y,gr->Max.y); + z.Fill(gr->Min.z,gr->Max.z); + mgl_surf3a_xyz(gr,&x,&y,&z,a,b,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_surf3a_xyz_val_(uintptr_t *gr, float *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) +void mgl_surf3a_xyz_val_(uintptr_t *gr, mreal *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_surf3a_xyz_val(_GR_, *Val, _DA_(x), _DA_(y), _DA_(z), _DA_(a), _DA_(b), s, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_surf3a_val_(uintptr_t *gr, float *Val, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) +void mgl_surf3a_val_(uintptr_t *gr, mreal *Val, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_surf3a_val(_GR_, *Val, _DA_(a), _DA_(b), s, o); delete []o; delete []s; } @@ -556,19 +541,16 @@ void mgl_surf3a_(uintptr_t *gr, uintptr_t *a, uintptr_t *b, const char *sch, con // Surf3C series // //----------------------------------------------------------------------------- -void mgl_surf3c_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *sch, const char *opt) +void mgl_surf3c_xyz_val(HMGL gr, mreal val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *sch, const char *opt) { long i,j,k,i1,n=a->GetNx(),m=a->GetNy(),l=a->GetNz(); long *kx1,*kx2,*ky1,*ky2,*kz; - bool both, wire = sch && strchr(sch,'#'); - float d; - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Surf3A"); return; } - both = x->GetNx()*x->GetNy()*x->GetNz()==n*m*l && y->GetNx()*y->GetNy()*y->GetNz()==n*m*l && z->GetNx()*z->GetNy()*z->GetNz()==n*m*l; - if(!(both || (x->GetNx()==n && y->GetNx()==m && z->GetNx()==l))) - { gr->SetWarn(mglWarnDim,"Surf3A"); return; } - if(b->GetNx()*b->GetNy()*b->GetNz()!=n*m*l) { gr->SetWarn(mglWarnDim,"Surf3A"); return; } + bool both = mgl_isboth(x,y,z,a), wire = sch && strchr(sch,'#'); + mreal d; + if(mgl_check_dim3(gr,both,x,y,z,a,b,"Surf3C")) return; + gr->SaveState(opt); - static int cgid=1; gr->StartGroup("Surf3A",cgid++); + static int cgid=1; gr->StartGroup("Surf3C",cgid++); bool inv = (sch && strchr(sch,'-')); long ss = gr->AddTexture(sch), pos; @@ -576,12 +558,12 @@ void mgl_surf3c_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT kx1 = new long[n*m]; kx2 = new long[n*m]; ky1 = new long[n*m]; ky2 = new long[n*m]; kz = new long[n*m]; - float c; + mreal c; std::vector kk; kk.reserve(n*m*l); - mglPoint p,q,u; - float a0,b0; + mglPoint p,q,u, p0; + mreal a0,b0; for(k=0;kv(i,j,k); b0 = b->v(i,j,k); + p0 = both?mglPoint(x->v(i,j,k), y->v(i,j,k), z->v(i,j,k)) : mglPoint(x->v(i), y->v(j), z->v(k)); if(iv(i+1,j,k)); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k)*(1-d)+x->v(i+1,j,k)*d, - y->v(i,j,k)*(1-d)+y->v(i+1,j,k)*d, - z->v(i,j,k)*(1-d)+z->v(i+1,j,k)*d); - else p = mglPoint(x->v(i)*(1-d)+x->v(i+1)*d, y->v(j), z->v(k)); + if(both) p = mglPoint(p0.x*(1-d)+x->v(i+1,j,k)*d, + p0.y*(1-d)+y->v(i+1,j,k)*d, + p0.z*(1-d)+z->v(i+1,j,k)*d); + else p = mglPoint(p0.x*(1-d)+x->v(i+1)*d, p0.y, p0.z); c = gr->GetC(ss,b0*(1-d)+b->v(i+1,j,k)*d); u = mglPoint(i+d,j,k); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); @@ -616,10 +599,10 @@ void mgl_surf3c_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT d = mgl_d(val,a0,a->v(i,j+1,k)); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k)*(1-d)+x->v(i,j+1,k)*d, - y->v(i,j,k)*(1-d)+y->v(i,j+1,k)*d, - z->v(i,j,k)*(1-d)+z->v(i,j+1,k)*d); - else p = mglPoint(x->v(i), y->v(j)*(1-d)+y->v(j+1)*d, z->v(k)); + if(both) p = mglPoint(p0.x*(1-d)+x->v(i,j+1,k)*d, + p0.y*(1-d)+y->v(i,j+1,k)*d, + p0.z*(1-d)+z->v(i,j+1,k)*d); + else p = mglPoint(p0.x, p0.y*(1-d)+y->v(j+1)*d, p0.z); c = gr->GetC(ss,b0*(1-d)+b->v(i,j+1,k)*d); u = mglPoint(i,j+d,k); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); @@ -633,10 +616,10 @@ void mgl_surf3c_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT d = mgl_d(val,a->v(i,j,k-1),a0); if(d>=0 && d<1) { - if(both) p = mglPoint(x->v(i,j,k-1)*(1-d)+x->v(i,j,k)*d, - y->v(i,j,k-1)*(1-d)+y->v(i,j,k)*d, - z->v(i,j,k-1)*(1-d)+z->v(i,j,k)*d); - else p = mglPoint(x->v(i), y->v(j), z->v(k-1)*(1-d)+z->v(k)*d); + if(both) p = mglPoint(x->v(i,j,k-1)*(1-d)+p0.x*d, + y->v(i,j,k-1)*(1-d)+p0.y*d, + z->v(i,j,k-1)*(1-d)+p0.z*d); + else p = mglPoint(p0.x, p0.y, z->v(k-1)*(1-d)+p0.z*d); c = gr->GetC(ss,b->v(i,j,k-1)*(1-d)+b0*d); u = mglPoint(i,j,k+d-1); q = mgl_find_norm(both, x,y,z,a, u, inv,n,m,l); @@ -653,46 +636,47 @@ void mgl_surf3c_xyz_val(HMGL gr, float val, HCDT x, HCDT y, HCDT z, HCDT a, HCDT delete []ky2; delete []kz; } //----------------------------------------------------------------------------- -void mgl_surf3c_val(HMGL gr, float val, HCDT a, HCDT b, const char *sch, const char *opt) +void mgl_surf3c_val(HMGL gr, mreal val, HCDT a, HCDT b, const char *sch, const char *opt) { - if(a->GetNx()<2 || a->GetNy()<2 || a->GetNz()<2) { gr->SetWarn(mglWarnLow,"Surf3C"); return; } gr->SaveState(opt); mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); x.Fill(gr->Min.x,gr->Max.x); y.Fill(gr->Min.y,gr->Max.y); z.Fill(gr->Min.z,gr->Max.z); mgl_surf3c_xyz_val(gr,val,&x,&y,&z,a,b,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surf3c_xyz(HMGL gr, HCDT x, HCDT y, HCDT z, HCDT a, HCDT b, const char *sch, const char *opt) { - float r = gr->SaveState(opt); + mreal r = gr->SaveState(opt); long num = mgl_isnan(r)?3:long(r+0.5); for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); + mreal v = gr->Max.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); mgl_surf3c_xyz_val(gr,v,x,y,z,a,b,sch,0); } + gr->LoadState(); } //----------------------------------------------------------------------------- void mgl_surf3c(HMGL gr, HCDT a, HCDT b, const char *sch, const char *opt) { - float r = gr->SaveState(opt); - long num = mgl_isnan(r)?3:long(r+0.5); - for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); - mgl_surf3c_val(gr,v,a,b,sch,0); - } + gr->SaveState(opt); + mglData x(a->GetNx()), y(a->GetNy()),z(a->GetNz()); + x.Fill(gr->Min.x,gr->Max.x); + y.Fill(gr->Min.y,gr->Max.y); + z.Fill(gr->Min.z,gr->Max.z); + mgl_surf3c_xyz(gr,&x,&y,&z,a,b,sch,0); + gr->LoadState(); } //----------------------------------------------------------------------------- -void mgl_surf3c_xyz_val_(uintptr_t *gr, float *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) +void mgl_surf3c_xyz_val_(uintptr_t *gr, mreal *Val, uintptr_t *x, uintptr_t *y, uintptr_t *z, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_surf3c_xyz_val(_GR_, *Val, _DA_(x), _DA_(y), _DA_(z), _DA_(a), _DA_(b), s, o); delete []o; delete []s; } //----------------------------------------------------------------------------- -void mgl_surf3c_val_(uintptr_t *gr, float *Val, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) +void mgl_surf3c_val_(uintptr_t *gr, mreal *Val, uintptr_t *a, uintptr_t *b, const char *sch, const char *opt,int l,int lo) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; char *o=new char[lo+1]; memcpy(o,opt,lo); o[lo]=0; mgl_surf3c_val(_GR_, *Val, _DA_(a), _DA_(b), s, o); delete []o; delete []s; } @@ -715,16 +699,73 @@ void mgl_surf3c_(uintptr_t *gr, uintptr_t *a, uintptr_t *b, const char *sch, con // flag & 0x1 -- accompanied coordinates // flag & 0x2 -- project to r*z // flag & 0x4 -- normalize field -void mgl_beam_val(HMGL gr, float val, HCDT tr, HCDT g1, HCDT g2, HCDT a, float r, const char *stl, int flag) +void mgl_beam_md(HMGL gr, mreal val, const mglData *tr, const mglData *g1, const mglData *g2, const mglData *a, mreal r, const char *stl, int flag) { + long n = a->nz,m=a->nx,l=a->ny; + if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Beam"); return; } + if(a->Minimal()<0) { gr->SetWarn(mglWarnNeg,"Beam"); return; } + if(tr->nx<3 || tr->nynx<3 || g1->nynx<3 || g2->nySetWarn(mglWarnDim,"Beam"); return; } + mglData x(a),y(a),z(a),b(a); + register long i,j,k,i0; + mreal asum=1, asum0=1, amax, aa; + r = fabs(r); + if(flag & 4) for(j=0;ja[j]*a->a[j]; + if(asum0==0) { gr->SetWarn(mglWarnZero,"Beam"); return; } + for(i=0;ia[j+m*l*i]; + asum += aa*aa; + amax = amax>aa ? amax : aa; + } + if(amax==0) { asum=0; amax=1; } + for(j=0;jStop) return; + i0 = j+m*(k+l*i); + if(flag & 1) + { + x.a[i0] = 2*j/(m-1.)-1; + y.a[i0] = 2*k/(l-1.)-1; + z.a[i0] = gr->Max.z*i/(n-1.); + } + else + { + x.a[i0] = tr->a[3*i] + g1->a[3*i]*(2*j/(m-1.)-1)*r + g2->a[3*i]*(2*k/(l-1.)-1)*r; + y.a[i0] = tr->a[3*i+1] + g1->a[3*i+1]*(2*j/(m-1.)-1)*r + g2->a[3*i+1]*(2*k/(l-1.)-1)*r; + z.a[i0] = tr->a[3*i+2] + g1->a[3*i+2]*(2*j/(m-1.)-1)*r + g2->a[3*i+2]*(2*k/(l-1.)-1)*r; + } + if(flag & 2) x.a[i0] = hypot(x.a[i0],y.a[i0]); + } + } + mgl_surf3_xyz_val(gr,val,&x,&y,&z,&b,stl,0); +} +//----------------------------------------------------------------------------- +void mgl_beam_val(HMGL gr, mreal val, HCDT tr, HCDT g1, HCDT g2, HCDT a, mreal r, const char *stl, int flag) +{ + + const mglData *dtr=dynamic_cast(tr); + const mglData *dg2=dynamic_cast(g1); + const mglData *dg1=dynamic_cast(g2); + const mglData *da=dynamic_cast(a); + if(dtr&&dg1&&dg2&&da) + { mgl_beam_md(gr,val,dtr,dg1,dg2,da,r,stl,flag); return; } + long n = a->GetNz(),m=a->GetNx(),l=a->GetNy(); - if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow); return; } - if(a->Minimal()<0) { gr->SetWarn(mglWarnNeg); return; } + if(n<2 || m<2 || l<2) { gr->SetWarn(mglWarnLow,"Beam"); return; } + if(a->Minimal()<0) { gr->SetWarn(mglWarnNeg,"Beam"); return; } if(tr->GetNx()<3 || tr->GetNy()GetNx()<3 || g1->GetNy()GetNx()<3 || g2->GetNy()SetWarn(mglWarnDim,"Beam"); return; } mglData x(a),y(a),z(a),b(a); register long i,j,k,i0; - float asum=1, asum0=1, amax, aa; + mreal asum=1, asum0=1, amax, aa; r = fabs(r); if(flag & 4) for(j=0;jvthr(j)*a->vthr(j); if(asum0==0) { gr->SetWarn(mglWarnZero,"Beam"); return; } @@ -764,21 +805,21 @@ void mgl_beam_val(HMGL gr, float val, HCDT tr, HCDT g1, HCDT g2, HCDT a, float r mgl_surf3_xyz_val(gr,val,&x,&y,&z,&b,stl,0); } //----------------------------------------------------------------------------- -void mgl_beam(HMGL gr, HCDT tr, HCDT g1, HCDT g2, HCDT a, float r, const char *stl, int flag, int num) +void mgl_beam(HMGL gr, HCDT tr, HCDT g1, HCDT g2, HCDT a, mreal r, const char *stl, int flag, int num) { num = num<=0 ? 1 : num; for(long i=0;iMax.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); + mreal v = gr->Max.c + (gr->Min.c-gr->Max.c)*(i+1.)/(num+1); mgl_beam_val(gr,v,tr,g1,g2,a,r,stl,flag); } } //----------------------------------------------------------------------------- -void mgl_beam_val_(uintptr_t *gr, float *val, uintptr_t *tr, uintptr_t *g1, uintptr_t *g2, uintptr_t *a, float *r, const char *sch, int *norm,int l) +void mgl_beam_val_(uintptr_t *gr, mreal *val, uintptr_t *tr, uintptr_t *g1, uintptr_t *g2, uintptr_t *a, mreal *r, const char *sch, int *norm,int l) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; mgl_beam_val(_GR_, *val,_DA_(tr),_DA_(g1),_DA_(g2),_DA_(a),*r,s,*norm); delete []s; } //----------------------------------------------------------------------------- -void mgl_beam_(uintptr_t *gr, uintptr_t *tr, uintptr_t *g1, uintptr_t *g2, uintptr_t *a, float *r, const char *sch, int *norm, int *num,int l) +void mgl_beam_(uintptr_t *gr, uintptr_t *tr, uintptr_t *g1, uintptr_t *g2, uintptr_t *a, mreal *r, const char *sch, int *norm, int *num,int l) { char *s=new char[l+1]; memcpy(s,sch,l); s[l]=0; mgl_beam(_GR_, _DA_(tr), _DA_(g1), _DA_(g2), _DA_(a), *r,s,*norm,*num); delete []s; } //----------------------------------------------------------------------------- diff --git a/texinfo/CMakeLists.txt b/texinfo/CMakeLists.txt index 9b6fc34..b3afc0f 100644 --- a/texinfo/CMakeLists.txt +++ b/texinfo/CMakeLists.txt @@ -1,107 +1,153 @@ - -# Warning!!!!! -# new files and destination for html docs. - if(MGL_HAVE_DOC) - set(MGL_PNG alpha.png area.png aspect.png axial.png axis.png barh.png bars.png belt.png boxplot.png - box.png boxs.png candle.png chart.png cloud.png colorbar.png combined.png cones.png conta.png contd.png - contfa.png contf.png contf_xyz.png cont.png contv.png cont_xyz.png curvcoor.png cut.png dat_diff.png - dat_extra.png densa.png dens.png dens_xyz.png dew.png dots.png error.png fall.png fit.png flow.png - fog.png grad.png hist.png inplot.png label.png legend.png loglog.png map.png mark.png mesh.png mirror.png - molecule.png parser.png pde.png pipe.png plot.png primitives.png qo2d.png radar.png region.png schemes.png - several_light.png stem.png step.png stereo.png stfa.png style.png surf3a.png surf3c.png surf3.png - surfa.png surfc.png surf.png tape.png tens.png ternary.png textmark.png text.png ticks.png tile.png - tiles.png torus.png traj.png triplot.png tube.png type0.png type1.png type2.png vect.png venn.png) + set(MGL_PNG alpha area aspect axial axis barh bars belt boxplot + box boxs candle chart cloud colorbar combined cones conta contd + contfa contf contf_xyz cont contv cont_xyz curvcoor cut dat_diff + dat_extra densa dens dens_xyz dew dots error fall fit flow + fog grad hist inplot label legend loglog map mark mesh mirror + molecule parser pde pipe plot primitives qo2d radar region schemes + several_light stem step stereo stfa style surf3a surf3c surf3 + surfa surfc surf tape tens ternary textmark text ticks tile + tiles torus traj triangulation triplot tube type0 type1 type2 vect venn ) + set(MGL_PNG_N ) + set(MGL_PNG_S ) -# foreach(SAMPLE ${MGL_PNG}) -# add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/texinfo/png/${SAMPLE} -# COMMAND ${CMAKE_BINARY_DIR}/examples/mgl_example --kind=${SAMPLE} -# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/texinfo/png ) -# endforeach(SAMPLE) + set(MGL_OUT ${CMAKE_BINARY_DIR}/texinfo) + set(MGL_TEX ${CMAKE_SOURCE_DIR}/texinfo) + file(MAKE_DIRECTORY ${MGL_OUT}/png) + file(MAKE_DIRECTORY ${MGL_OUT}/small) + file(COPY ${MGL_TEX}/qt.png ${MGL_TEX}/fltk.png ${MGL_TEX}/classes.png DESTINATION ${MGL_OUT}) + file(COPY ${MGL_TEX}/toc_ru.html ${MGL_TEX}/toc_fr.html ${MGL_TEX}/toc_en.html ${MGL_TEX}/title.html ${MGL_TEX}/index.html DESTINATION ${MGL_OUT}) + + foreach(SAMPLE ${MGL_PNG}) + set(MGL_PNG_N ${MGL_PNG_N} ${MGL_OUT}/png/${SAMPLE}.png) + add_custom_command(OUTPUT ${MGL_OUT}/png/${SAMPLE}.png + COMMAND ${CMAKE_BINARY_DIR}/examples/mgl_example -kind=${SAMPLE} + DEPENDS mgl_example + WORKING_DIRECTORY ${MGL_OUT}/png ) + set(MGL_PNG_S ${MGL_PNG_S} ${MGL_OUT}/small/${SAMPLE}-sm.png) + add_custom_command(OUTPUT ${MGL_OUT}/small/${SAMPLE}-sm.png + COMMAND ${CMAKE_BINARY_DIR}/examples/mgl_example -kind=${SAMPLE} -mini + DEPENDS mgl_example + WORKING_DIRECTORY ${MGL_OUT}/small ) + endforeach(SAMPLE) - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/texinfo/png/all.png - COMMAND ${CMAKE_BINARY_DIR}/examples/mgl_example - COMMAND touch ${CMAKE_SOURCE_DIR}/texinfo/png/all.png - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/texinfo/png - ) - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/texinfo/small/all.png - COMMAND ${CMAKE_BINARY_DIR}/examples/mgl_example -mini - COMMAND touch ${CMAKE_SOURCE_DIR}/texinfo/small/all.png - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/texinfo/small - ) -# set_source_files_properties(${CMAKE_BINARY_DIR}/examples/mgl_example PROPERTIES GENERATED 1) -# ADD_CUSTOM_TARGET(gen_all_png DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/png/all.png) -# ADD_DEPENDENCIES(gen_all_png mgl_example) set(list_texi_files_en mathgl_en.texi mgl_en.texi overview_en.texi example_en.texi ex_mgl_en.texi parse_en.texi core_en.texi concept_en.texi widget_en.texi data_en.texi other_en.texi appendix_en.texi fdl.texi) set(list_texi_files_ru mathgl_ru.texi mgl_ru.texi overview_ru.texi example_ru.texi ex_mgl_ru.texi parse_ru.texi core_ru.texi concept_ru.texi widget_ru.texi data_ru.texi other_ru.texi appendix_ru.texi fdl.texi) - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/texinfo/web_en.pdf - COMMAND ${findtp} -I ${CMAKE_SOURCE_DIR}/texinfo/png web_en.texi - COMMAND ${findth} -I=${CMAKE_SOURCE_DIR}/texinfo/png --split=section web_en.texi -o web_en - DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/small/all.png web_en.texi - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/texinfo - ) + add_custom_command(OUTPUT ${MGL_OUT}/web_en.pdf + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/web_en.texi + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/web_en.texi + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/web_en.texi + DEPENDS web_en.texi ${MGL_PNG_S} + WORKING_DIRECTORY ${MGL_OUT} + ) + add_custom_command(OUTPUT ${MGL_OUT}/web_en/web_en.html + COMMAND ${findth} -I=${MGL_OUT}/png --split=section -o web_en ${MGL_TEX}/web_en.texi + DEPENDS web_en.texi ${MGL_PNG_S} + WORKING_DIRECTORY ${MGL_OUT} + ) - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/texinfo/mathgl_en.info - COMMAND ${findth} -I=${CMAKE_SOURCE_DIR}/texinfo/png --split=section mathgl_en.texi -o mathgl_en - COMMAND ${findth} -I=${CMAKE_SOURCE_DIR}/texinfo/png --split=node --frames -o doc_en mathgl_en.texi - COMMAND ${findth} -I=${CMAKE_SOURCE_DIR}/texinfo/png --split=no mgl_en.texi -o mgl_en.html - COMMAND ${findmi} --no-validate mathgl_en.texi - DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/png/all.png - DEPENDS ${list_texi_files_en} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/texinfo + add_custom_command(OUTPUT ${MGL_OUT}/mathgl_en.info + COMMAND ${findmi} --no-validate ${MGL_TEX}/mathgl_en.texi + DEPENDS ${list_texi_files_en} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} ) - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/texinfo/mathgl_ru.info - COMMAND ${findth} -I=${CMAKE_SOURCE_DIR}/texinfo/png --split=section mathgl_ru.texi -o mathgl_ru - COMMAND ${findth} -I=${CMAKE_SOURCE_DIR}/texinfo/png --split=node --frames -o doc_ru mathgl_ru.texi - COMMAND ${findth} -I=${CMAKE_SOURCE_DIR}/texinfo/png --split=no mgl_ru.texi -o mgl_ru.html - COMMAND ${findmi} --no-validate mathgl_ru.texi - DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/png/all.png - DEPENDS ${list_texi_files_ru} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/texinfo + add_custom_command(OUTPUT ${MGL_OUT}/mathgl_en/mathgl_en.html + COMMAND ${findth} -I=${MGL_OUT}/png --split=section -o mathgl_en ${MGL_TEX}/mathgl_en.texi + DEPENDS ${list_texi_files_en} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} ) - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/texinfo/mathgl_en.pdf - COMMAND ${findtp} -I ${CMAKE_SOURCE_DIR}/texinfo/png mathgl_en.texi - COMMAND ${findtp} -I ${CMAKE_SOURCE_DIR}/texinfo/png mathgl_en.texi - COMMAND ${findtp} -I ${CMAKE_SOURCE_DIR}/texinfo/png mathgl_en.texi - DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/png/all.png - DEPENDS ${list_texi_files_en} -# DEPENDS ${list_texi_files_ru} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/texinfo + add_custom_command(OUTPUT ${MGL_OUT}/doc_en/doc_en.html + COMMAND ${findth} -I=${MGL_OUT}/png --split=node --frames -o doc_en ${MGL_TEX}/doc_en.texi + DEPENDS ${list_texi_files_en} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} ) - add_custom_target(documentation ALL - DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/mathgl_en.info - DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/mathgl_en.pdf - DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/web_en.pdf -# DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/mathgl_ru.info -# DEPENDS ${CMAKE_SOURCE_DIR}/texinfo/mathgl_ru.pdf + add_custom_command(OUTPUT ${MGL_OUT}/mgl_en.html + COMMAND ${findth} -I=${MGL_OUT}/png --split=no -o mgl_en.html ${MGL_TEX}/mgl_en.texi + DEPENDS ${list_texi_files_en} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} + ) + + add_custom_command(OUTPUT ${MGL_OUT}/mathgl_en.pdf + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/mathgl_en.texi + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/mathgl_en.texi + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/mathgl_en.texi + DEPENDS ${list_texi_files_en} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} + ) + + add_custom_command(OUTPUT ${MGL_OUT}/web_ru.pdf + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/web_ru.texi + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/web_ru.texi + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/web_ru.texi + DEPENDS web_ru.texi ${MGL_PNG_S} + WORKING_DIRECTORY ${MGL_OUT} + ) + add_custom_command(OUTPUT ${MGL_OUT}/web_ru/web_ru.html + COMMAND ${findth} -I=${MGL_OUT}/png --split=section -o web_ru ${MGL_TEX}/web_ru.texi + DEPENDS web_ru.texi ${MGL_PNG_S} + WORKING_DIRECTORY ${MGL_OUT} ) - add_custom_target(clean - COMMAND rm -f mathgl*.[hali]* mathgl*.?? mathgl_*/* *~ #png/*.png - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/texinfo + + add_custom_command(OUTPUT ${MGL_OUT}/mathgl_ru.info + COMMAND ${findmi} --no-validate ${MGL_TEX}/mathgl_ru.texi + DEPENDS ${list_texi_files_ru} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} + ) + add_custom_command(OUTPUT ${MGL_OUT}/mathgl_ru/mathgl_ru.html + COMMAND ${findth} -I=${MGL_OUT}/png --split=section -o mathgl_ru ${MGL_TEX}/mathgl_ru.texi + DEPENDS ${list_texi_files_ru} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} + ) + add_custom_command(OUTPUT ${MGL_OUT}/doc_ru/doc_ru.html + COMMAND ${findth} -I=${MGL_OUT}/png --split=node --frames -o doc_ru ${MGL_TEX}/doc_ru.texi + DEPENDS ${list_texi_files_ru} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} + ) + add_custom_command(OUTPUT ${MGL_OUT}/mgl_ru.html + COMMAND ${findth} -I=${MGL_OUT}/png --split=no -o mgl_ru.html ${MGL_TEX}/mgl_ru.texi + DEPENDS ${list_texi_files_ru} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} + ) + + add_custom_command(OUTPUT ${MGL_OUT}/mathgl_ru.pdf + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/mathgl_ru.texi + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/mathgl_ru.texi + COMMAND ${findtp} -I ${MGL_OUT}/png ${MGL_TEX}/mathgl_ru.texi + DEPENDS ${list_texi_files_ru} ${MGL_PNG_N} + WORKING_DIRECTORY ${MGL_OUT} + ) + + add_custom_target(documentation ALL + DEPENDS ${MGL_OUT}/mathgl_en.info + DEPENDS ${MGL_OUT}/mathgl_en.pdf + DEPENDS ${MGL_OUT}/mgl_en.html + DEPENDS ${MGL_OUT}/mathgl_en/mathgl_en.html + + DEPENDS ${MGL_OUT}/doc_en/doc_en.html + DEPENDS ${MGL_OUT}/web_en/web_en.html + +# DEPENDS ${MGL_OUT}/mathgl_ru.info +# DEPENDS ${MGL_OUT}/mathgl_ru.pdf + DEPENDS ${MGL_OUT}/mgl_ru.html + DEPENDS ${MGL_OUT}/mathgl_ru/mathgl_ru.html + +# DEPENDS ${MGL_OUT}/doc_ru/doc_ru.html +# DEPENDS ${MGL_OUT}/web_ru/web_ru.html ) - install(DIRECTORY ./ DESTINATION ${MGL_DOC_PATH} - FILES_MATCHING PATTERN ".svn" EXCLUDE - PATTERN "CMakeFiles" EXCLUDE - PATTERN "*.png" - PATTERN "*.html" - PATTERN "*/*.html" - PATTERN "./mathgl*.info*" - PATTERN "./mathgl*.pdf") - install(DIRECTORY ./ DESTINATION ${MGL_MAN_PATH}/man1 - FILES_MATCHING PATTERN ".svn" EXCLUDE - PATTERN "CMakeFiles" EXCLUDE - PATTERN "*_en" EXCLUDE - PATTERN "png" EXCLUDE - PATTERN "small" EXCLUDE - PATTERN "*.1") - install(DIRECTORY ./ DESTINATION ${MGL_MAN_PATH}/man5 - FILES_MATCHING PATTERN ".svn" EXCLUDE - PATTERN "CMakeFiles" EXCLUDE - PATTERN "*_en" EXCLUDE - PATTERN "png" EXCLUDE - PATTERN "small" EXCLUDE - PATTERN "*.5") +# add_custom_target(clean +# COMMAND rm -f * */* +# WORKING_DIRECTORY ${MGL_OUT} +# ) + set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "doc_en;mathgl_en;web_en;./mathgl*.*;small/*.*;png/*.*") + install(FILES ${MGL_TEX}/qt.png ${MGL_TEX}/fltk.png ${MGL_TEX}/classes.png DESTINATION ${MGL_DOC_PATH}) + install(FILES ${MGL_OUT}/mathgl_en.pdf ${MGL_OUT}/mgl_en.html DESTINATION ${MGL_DOC_PATH}) + install(DIRECTORY ${MGL_OUT}/mathgl_en DESTINATION ${MGL_DOC_PATH}) + install(DIRECTORY ${MGL_OUT}/png DESTINATION ${MGL_DOC_PATH}) + install(FILES ${MGL_TEX}/mglconv.1 ${MGL_TEX}/mglview.1 DESTINATION ${MGL_MAN_PATH}/man1) + install(FILES ${MGL_TEX}/mgl.5 DESTINATION ${MGL_MAN_PATH}/man5) +# TODO: try to install all mathgl*.info* in future!!! + install(FILES ${MGL_OUT}/mathgl_en.info ${MGL_OUT}/mathgl_en.info-1 ${MGL_OUT}/mathgl_en.info-2 DESTINATION ${MGL_INFO_PATH}) endif(MGL_HAVE_DOC) diff --git a/texinfo/concept_en.texi b/texinfo/concept_en.texi index d7b9bdf..0524431 100644 --- a/texinfo/concept_en.texi +++ b/texinfo/concept_en.texi @@ -13,7 +13,7 @@ There are six most general (base) concepts: @item @strong{All functions have ``simplified'' and ``advanced'' forms.} It is done for user's convenience. One needs to specify only one data array in the ``simplified'' form in order to see the result. But one may set parametric dependence of coordinates and produce rather complex curves and surfaces in the ``advanced'' form. In both cases the order of function arguments is the same: first data arrays, second the string with style, and later string with options for additional plot tuning. @item -@strong{All data arrays for plotting are encapsulated in mglData(A) class.} This reduces the number of errors while working with memory and provides a uniform interface for data of different types (float, double and so on) or for formula plotting. +@strong{All data arrays for plotting are encapsulated in mglData(A) class.} This reduces the number of errors while working with memory and provides a uniform interface for data of different types (mreal, double and so on) or for formula plotting. @item @strong{All plots are vector plots.} The MathGL library is intended for handling scientific data which have vector nature (lines, faces, matrices and so on). As a result, vector representation is used in all cases! In addition, the vector representation allows one to scale the plot easily -- change the canvas size by a factor of 2, and the picture will be proportionally scaled. @item @@ -34,10 +34,11 @@ In addition to the general concepts I want to comment on some non-trivial or les @end menu @c ------------------------------------------------------------------ +@external @node Coordinate axes, Color styles, , General concepts @section Coordinate axes -Two axis representations are used in MathGL. The first one consists of normalizing coordinates of data points in a box @var{Min} x @var{Max} (see @ref{Axis settings}). If @code{SetCut()} is @code{true} then the outlier points are omitted, otherwise they are projected to the bounding box (see @ref{Cutting}). Also, the point will be omitted if it lies inside the box defined by @code{SetCutBox()} or if the value of formula @code{CutOff()} is nonzero for its coordinates. After that, transformation formulas defined by @code{SetFunc()} or @code{SetCoor()} are applied to the data point (see @ref{Curved coordinates}). Finally, the data point is plotted by one of the functions. +Two axis representations are used in MathGL. The first one consists of normalizing coordinates of data points in a box @var{Min}x@var{Max} (see @ref{Axis settings}). If @code{SetCut()} is @code{true} then the outlier points are omitted, otherwise they are projected to the bounding box (see @ref{Cutting}). Also, the point will be omitted if it lies inside the box defined by @code{SetCutBox()} or if the value of formula @code{CutOff()} is nonzero for its coordinates. After that, transformation formulas defined by @code{SetFunc()} or @code{SetCoor()} are applied to the data point (see @ref{Curved coordinates}). Finally, the data point is plotted by one of the functions. The range of @emph{x, y, z}-axis can be specified by @code{SetRange()} or @code{SetRanges()} functions. Its origin is specified by @code{SetOrigin()} function. At this you can you can use @code{NAN} values for selecting axis origin automatically. @@ -45,14 +46,15 @@ There is 4-th axis @emph{c} (color axis or colorbar) in addition to the usual ax The form (appearence) of tick labels is controlled by @code{SetTicks()} function (@pxref{Ticks}). Function @var{SetTuneTicks} switches on/off tick enhancing by factoring out acommon multiplier (for small coordinate values, like 0.001 to 0.002, or large, like from 1000 to 2000) or common component (for narrow range, like from 0.999 to 1.000). Finally, you may use functions @code{SetTickTempl()} for setting templates for tick labels (it supports TeX symbols). Also, there is a possibility to print arbitrary text as tick labels the by help of @code{SetTicksVal()} function. - +@c ------------------------------------------------------------------ +@external @node Color styles, Line styles, Coordinate axes, General concepts @section Color styles Base colors are defined by one of symbol @samp{wkrgbcymhRGBCYMHWlenupqLENUPQ}. @ifhtml @html -The color types are: ‘k’ -- black, ‘r’ -- red, ‘R’ -- dark red, ‘g’ -- green, ‘G’ -- dark green, ‘b’ -- blue, ‘B’ -- dark blue, ‘c’ -- cyan, ‘C’ -- dark cyan, ‘m’ -- magenta, ‘M’ -- dark magenta, ‘y’ -- yellow, ‘Y’ -- dark yellow (gold), ‘h’ -- gray, ‘H’ -- dark gray, ‘w’ -- white, ‘W’ -- bright gray, ‘l’ -- green-blue, ‘L’ -- dark green-blue, ‘e’ -- green-yellow, ‘E’ -- dark green-yellow, ‘n’ -- sky-blue, ‘N’ -- dark sky-blue, ‘u’ -- blue-violet, ‘U’ -- dark blue-violet, ‘p’ -- purple, ‘P’ -- dark purple, ‘q’ -- orange, ‘Q’ -- dark orange (brown).

+

The color types are: ‘k’ -- black, ‘r’ -- red, ‘R’ -- dark red, ‘g’ -- green, ‘G’ -- dark green, ‘b’ -- blue, ‘B’ -- dark blue, ‘c’ -- cyan, ‘C’ -- dark cyan, ‘m’ -- magenta, ‘M’ -- dark magenta, ‘y’ -- yellow, ‘Y’ -- dark yellow (gold), ‘h’ -- gray, ‘H’ -- dark gray, ‘w’ -- white, ‘W’ -- bright gray, ‘l’ -- green-blue, ‘L’ -- dark green-blue, ‘e’ -- green-yellow, ‘E’ -- dark green-yellow, ‘n’ -- sky-blue, ‘N’ -- dark sky-blue, ‘u’ -- blue-violet, ‘U’ -- dark blue-violet, ‘p’ -- purple, ‘P’ -- dark purple, ‘q’ -- orange, ‘Q’ -- dark orange (brown).

@end html @end ifhtml @ifnothtml @@ -61,7 +63,8 @@ The color types are: @samp{k} -- black, @samp{r} -- red, @samp{R} -- dark red, @ You can also use ``bright'' colors. The ``bright'' color contain 2 symbols in brackets @samp{@{cN@}}: first one is the usual symbol for color id, the second one is a digit for its brightness. The digit can be in range @samp{1}...@samp{9}. Number @samp{5} corresponds to a normal color, @samp{1} is a very dark version of the color (practically black), and @samp{9} is a very bright version of the color (practically white). For example, the colors can be @samp{@{b2@}} @samp{@{b7@}} @samp{@{r7@}} and so on. - +@c ------------------------------------------------------------------ +@external @node Line styles, Color scheme, Color styles, General concepts @section Line styles @@ -87,9 +90,10 @@ Marker types are: @samp{o} -- circle, @samp{+} -- cross, @samp{x} -- skew cross, One may specify to draw a special symbol (an arrow) at the beginning and at the end of line. This is done if the specification string contains one of the following symbols: @samp{A} -- outer arrow, @samp{V} -- inner arrow, @samp{I} -- transverse hatches, @samp{K} -- arrow with hatches, @samp{T} -- triangle, @samp{S} -- square, @samp{D} -- rhombus, @samp{O} -- circle, @samp{_} -- nothing (the default). The following rule applies: the first symbol specifies the arrow at the end of line, the second specifies the arrow at the beginning of the line. For example, @samp{r-A} defines a red solid line with usual arrow at the end, @samp{b|AI} defines a blue dash line with an arrow at the end and with hatches at the beginning, @samp{_O} defines a line with the current style and with a circle at the beginning. These styles are applicable during the graphics plotting as well (for example, @ref{1D plotting}). -@fig{png/style, Color and line styles.} +@pfig{style, Color and line styles.} @c ------------------------------------------------------------------ +@external @node Color scheme, Font styles, Line styles, General concepts @section Color scheme @@ -101,12 +105,13 @@ The final color is a linear interpolation of color array. The color array is con There are several useful combinations. String @samp{kw} corresponds to the simplest gray color scheme where higher values are brighter. String @samp{wk} presents the inverse gray color scheme where higher value is darker. Strings @samp{kRryw}, @samp{kGgw}, @samp{kBbcw} present the well-known @emph{hot}, @emph{summer} and @emph{winter} color schemes. Strings @samp{BbwrR} and @samp{bBkRr} allow to view bi-color figure on white or black background, where negative values are blue and positive values are red. String @samp{BbcyrR} gives a color scheme similar to the well-known @emph{jet} color scheme. -@fig{png/schemes, Most popular color schemes.} +@pfig{schemes, Most popular color schemes.} When coloring by @emph{coordinate} (used in @ref{map}), the final color is determined by the position of the point in 3d space and is calculated from formula c=x*c[1] + y*c[2]. Here, c[1], c[2] are the first two elements of color array; x, y are normalized to axis range coordinates of the point. @c This type of coloring is useful for isosurface plot where color may show the exact position of a piece of surface. @c ------------------------------------------------------------------ +@external @node Font styles, Textual formulas, Color scheme, General concepts @section Font styles @@ -145,8 +150,8 @@ The small part of most common special TeX symbols are: @math{\angle} -- \angle, The font size can be defined explicitly (if @var{size}>0) or relatively to a base font size as |@var{size}|*@var{FontSize} (if @var{size}<0). The value @var{size}=0 specifies that the string will not be printed. The base font size is measured in internal ``MathGL'' units. Special functions @code{SetFontSizePT(), SetFontSizeCM(), SetFontSizeIN()} (see @ref{Font settings}) allow one to set it in more ``common'' variables for a given dpi value of the picture. - @c ------------------------------------------------------------------ +@external @node Textual formulas, Command options, Font styles, General concepts @section Textual formulas @@ -168,7 +173,6 @@ The basic functions are: @samp{sqrt(x)} -- square root of @var{x}, @samp{pow(x,y @math{\pi=3.1415926...} @end ifnothtml - Trigonometric functions are: @samp{sin(x)}, @samp{cos(x)}, @samp{tan(x)} (or @samp{tg(x)}). Inverse trigonometric functions are: @samp{asin(x)}, @samp{acos(x)}, @samp{atan(x)}. Hyperbolic functions are: @samp{sinh(x)} (or @samp{sh(x)}), @samp{cosh(x)} (or @samp{ch(x)}), @samp{tanh(x)} (or @samp{th(x)}). Inverse hyperbolic functions are: @samp{asinh(x)}, @samp{acosh(x)}, @samp{atanh(x)}. @ifhtml @@ -198,8 +202,8 @@ Note, some of these functions are unavailable if MathGL was compiled without GSL There is no difference between lower or upper case in formulas. If argument value lie outside the range of function definition then function returns NaN. - @c ------------------------------------------------------------------ +@external @node Command options, Interfaces, Textual formulas, General concepts @section Command options @@ -259,6 +263,8 @@ Set the value to be used as additional numeric parameter in plotting command. +@c ------------------------------------------------------------------ +@external @node Interfaces, , Command options, General concepts @section Interfaces @@ -279,6 +285,7 @@ Finally, a special command language MGL (see @ref{MGL scripts}) was written for * C++ interface:: @end menu +@external @node C interface, C++ interface, , Interfaces @subsection C/Fortran interface @@ -297,6 +304,7 @@ These variables contain identifiers for graphics drawing objects and for the dat Fortran functions/subroutines have the same names as C functions. However, there is a difference. Variable of type @code{HMGL, HMDT} must be an integer with sufficient size (@code{integer*4} in the 32-bit operating system or @code{integer*8} in the 64-bit operating system). All C functions are subroutines in Fortran, which are called by operator @code{call}. The exceptions are functions, which return variables of types @code{HMGL} or @code{HMDT}. These functions should be declared as integer in Fortran code. Also, one should keep in mind that strings in Fortran are denoted by @code{'} symbol, not the @code{"} symbol. +@external @node C++ interface, , C interface, Interfaces @subsection C++/Python interface @@ -330,3 +338,6 @@ a.WritePNG("test.png") This becomes useful if you create many @code{mglData} objects, for example. @end ifclear + +@external + diff --git a/texinfo/concept_ru.texi b/texinfo/concept_ru.texi index d2407ea..9525114 100644 --- a/texinfo/concept_ru.texi +++ b/texinfo/concept_ru.texi @@ -1,20 +1,70 @@ +@chapter Основные принципы + +Возможности библиотеки MathGL довольно богаты -- число только основных типов графиков превышает 50 видов. Кроме того, есть функции для обработки данных, настройки вида графика и пр. и пр. Тем не менее, я старался придерживаться единого стиля в порядке аргументов функций и способе их ``настройки''. В основном все ниже сказанное относится к функциям рисования различных графиков. + +Всего основных концепций (базисных идей) шесть: +@enumerate +@item +@strong{Все рисунки создаются в памяти.} Это могут быть как растровые картинки (для @code{SetQuality(MGL_DRAW_LMEM)}), так и векторные списки примитивов (по умолчанию). Дальнейшая судьба рисунков определяется пользователем: можно сохранить в файл, вывести на экран, создать анимацию/кино, дополнительно отредактировать и т.д. Такой подход обеспечивает высокую переносимость библиотеки -- один и тот же программный код создаст в точности одинаковый рисунок на @emph{любой} операционной системе. Кроме того, при таком подходе рисунки можно создавать непосредственно в консольной программе -- графическое окно не нужно! +@item +@strong{Все настройки графиков (стиль линий, цветовые схемы поверхностей, стиль и цвет текста) задаются строками.} Это обеспечивает: удобство для пользователя -- короткую строку легче читать и здесь тяжелее ошибиться, чем в большом списке параметров; переносимость -- строки выглядят одинаково на всех платформах и не надо заботиться о типе и числе аргументов. +@item +@strong{Все функции имеют ``упрощенный'' и ``продвинутый'' варианты.} Сделано опять из-за удобства. В ``упрощенном'' варианте для построения графика нужны только один-два массив(а) данных, которые автоматически равнораспределяются в заданном диапазоне осей координат. В ``продвинутой'' версии можно не только указать явно диапазон построения графика, но и задать его параметрически. Последнее позволяет легко строить довольно сложные кривые и поверхности. В обоих вариантах функций порядок аргументов стандартен: сначала идут массивы данных, потом необязательный строковый параметр стиля графика, а далее строка опций для более точной настройки графика. +@item +@strong{Все данные передаются через экземпляры класса mglData(A).} Такой подход позволяет избежать ошибок при работе с памятью и единообразно передавать данные разных типов (mreal, double, данные из файла, заполненных пользователем и пр.) в функции рисования. +@item +@strong{Все элементы рисунков векторные.} Изначально библиотека MathGL была ориентированна на работу с научными данными, которые по своей природе векторные (линии, грани, матрицы и т.д.). Поэтому векторность используется во всех рисунках! Причем иногда даже в ущерб производительности (например, при выводе шрифтов). Помимо всего прочего, векторность позволяет легко масштабировать рисунок -- измените размер картинки в 2 раза, и рисунок пропорционально растянется. +@item +@strong{Новые графики не удаляют уже нарисованное.} Этот, в чем-то неожиданный, подход позволяет создавать огромное количество ``комбинированных'' графиков. Например, поверхность с наложенными линиями уровня строится двумя последовательными вызовами функций рисования поверхности и линий уровня (в любом порядке). И совершенно не надо писать специальную функцию (как в Matlab и некоторых других программах) для рисования этого графика. +@end enumerate + +Кроме основных концепций я хотел бы остановиться на нескольких, как оказалось, нетривиальных моментах -- способе указания положения графика, осей координат и строковых параметров линий, поверхностей, текста. + +@menu +* Coordinate axes:: +* Color styles:: +* Line styles:: +* Color scheme:: +* Font styles:: +* Textual formulas:: +* Command options:: +* Interfaces:: +@end menu + @c ------------------------------------------------------------------ -@node Coordinate axes, Line styles, , General concepts -@subsection Оси координат +@external +@node Coordinate axes, Color styles, , General concepts +@section Оси координат + +Представление системы координат в MathGL состоит из двух частей. Вначале координаты нормируются в интервал @var{Min}x@var{Max} (@pxref{Axis settings}). Если флаг @code{SetCut()} установлен, то точки вне интервала отбрасываются, в противном случае, они проецируются на ограничивающий параллелепипед (см. @ref{Cutting}). Кроме того, отбрасываются точки внутри границ, определенных переменными @var{CutMin}x@var{CutMax} и точки, для которых значение функции @code{CutOff}() не равно нулю. После этого формулы перехода в криволинейную систему координат @code{SetFunc()}применяются к каждой точке. Наконец, точка данных отображается с помощью одной из графических функций. -Представление системы координат в MathGL состоит из двух частей. Вначале координаты нормируются в интервал @var{Min}x@var{Max} (@pxref{Axis settings}). Если флаг @var{Cut} установлен, то точки вне интервала отбрасываются, в противном случае, они проецируются на ограничивающий параллелепипед (@pxref{Cutting}). Кроме того, отбрасываются точки внутри границ, определенных переменными @var{CutMin}x@var{CutMax} и точки, для которых значение функции @code{CutOff}() не равно нулю. После этого формулы перехода в криволинейную систему координат @code{SetFunc()}применяются к каждой точке. Наконец, точка данных отображается с помощью одной из графических функций. +Диапазон изменения @emph{x, y, z}-координат задается функциями @code{SetRange()} или @code{SetRanges()}. Точка пересечения осей координат задается функцией @code{SetOrigin()}. При этом можно использовать NAN значения для автоматического выбора положения оси. -Величины @var{Max}, @var{Min} можно изменять вручную. Однако, после этого необходимо вызвать функцию @code{RecalcBorder()} для настройки графика. Более удобный и безопасный путь состоит в вызове функций @code{Axis(), SetRanges()} и др. В последнем случае функция @code{RecalcBorder()} вызывается автоматически. Размеры осей можно задавать и автоматически по минимальному и максимальному значениям массива данных. Для этого предназначены функции @code{XRange(), YRange(), ZRange()}. Второй не обязательный аргумент указывает, заменять ли новые значения диапазона изменения оси координат (по умолчанию) или только расширить уже существующий диапазон. +Кроме привычных осей @emph{x, y, z} есть еще одна ось -- цветовая шкала -- ось @emph{c}. Она используется при окрашивании поверхностей и задает границы изменения функции при окрашивании. Ее границы автоматически устанавливаются равными Min.z и Max.z при вызове @code{SetRanges()}. Возможно и ручное изменение границ цветового интервала посредством вызова @code{SetRange('c', ...)}. Используйте @code{Colorbar()} для отображения цветовой шкалы. -Точка пересечения осей координат задается переменной @var{Org} и действует на последующие вызовы функций рисования осей координат и сетки. По умолчанию, если точка пересечения осей координат попадает вне диапазона осей координат, то она проецируется на границу области. Изменить такое поведение можно, задав @var{AutoOrg}=@code{false}. В случае, если одно из значений @var{Org} равно NAN, то соответствующее значение будет выбрано автоматически. +Вид меток по осям определяется функцией @code{SetTicks()} (@pxref{Ticks}). Функция @var{SetTuneTicks} включает/выключает выделение общего множителя (большого или малого факторов в диапазоне) для меток осей координат. Наконец, если стандартный вид меток не устраивает пользователя, то их шаблон можно задать явно (можно использовать и ТеХ символы), воспользовавшись функцией @code{SetTickTempl()}. Кроме того, в качестве меток можно вывести произвольный текст использовав функцию @code{SetTicksVal()}. -Кроме привычных осей @emph{x, y, z} есть еще одна ось -- цветовая шкала -- ось @emph{c}. Она используется при окрашивании поверхностей и задает границы изменения функции при окрашивании. При вызове @code{Axis()} ее границы автоматически устанавливаются равными Min.z и Max.z. Возможно и ручное изменение границ цветового интервала посредством вызова функции @code{CAxis()} или изменение границ по заданному массиву @code{CRange()}. Используйте @code{Colorbar()} для отображения цветовой шкалы. +@c ------------------------------------------------------------------ +@external +@node Color styles, Line styles, Coordinate axes, General concepts +@section Цвета + +Base colors are defined by one of symbol @samp{wkrgbcymhRGBCYMHWlenupqLENUPQ}. +@ifhtml +@html +

Символы цвета: ‘k’ -- черный, ‘r’ -- красный, ‘R’ -- темно красный, ‘g’ -- зеленый, ‘G’ -- темно зеленый, ‘b’ -- синий, ‘B’ -- темно синий, ‘c’ -- голубой, ‘C’ -- темно голубой, ‘m’ -- пурпурный, ‘M’ -- темно пурпурный, ‘y’ -- желтый, ‘Y’ -- темно желтый (золотой), ‘h’ -- серый, ‘H’ -- темно серый, ‘w’ -- белый, ‘W’ -- светло серый, ‘l’ -- сине-зеленый, ‘L’ -- темно сине-зеленый, ‘e’ -- желто-зеленый, ‘E’ -- темно желто-зеленый, ‘n’ -- небесно-синий, ‘N’ -- темно небесно-синий, ‘u’ -- сине-фиолетовый, ‘U’ -- темно сине-фиолетовый, ‘p’ -- фиолетовый, ‘P’ -- темно фиолетовый, ‘q’ -- оранжевый, ‘Q’ -- темно оранжевый (коричневый).

+@end html +@end ifhtml +@ifnothtml +Символы цвета: @samp{k} -- черный, @samp{r} -- красный, @samp{R} -- темно красный, @samp{g} -- зеленый, @samp{G} -- темно зеленый, @samp{b} -- синий, @samp{B} -- темно синий, @samp{c} -- голубой, @samp{C} -- темно голубой, @samp{m} -- пурпурный, @samp{M} -- темно пурпурный, @samp{y} -- желтый, @samp{Y} -- темно желтый (золотой), @samp{h} -- серый, @samp{H} -- темно серый, @samp{w} -- белый, @samp{W} -- светло серый, @samp{l} -- сине-зеленый, @samp{L} -- темно сине-зеленый, @samp{e} -- желто-зеленый, @samp{E} -- темно желто-зеленый, @samp{n} -- небесно-синий, @samp{N} -- темно небесно-синий, @samp{u} -- сине-фиолетовый, @samp{U} -- темно сине-фиолетовый, @samp{p} -- фиолетовый, @samp{P} -- темно фиолетовый, @samp{q} -- оранжевый, @samp{Q} -- темно оранжевый (коричневый). +@end ifnothtml -Вид меток по осям определяется функцией @code{SetTicks()} (@pxref{Axis settings}). Она имеет 3 аргумента: первый @var{d} задает шаг меток (если положительны) или их число (если отрицательны) или логарифмические метки (если равны нулю); второ @var{ns} задает число "подметок"; последний определяет начальную точку для меток (по умолчанию это точка пересечения осей). Функция @var{SetTuneTicks} включает/выключает выделение общего множителя (большого или малого факторов в диапазоне) для меток осей координат. Наконец, если стандартный вид меток не устраивает пользователя, то их шаблон можно задать явно (можно использовать и ТеХ символы), воспользовавшись функциями @code{SetXTT(), SetYTT(). SetZTT(). SetCTT()}. Кроме того, в качестве меток можно вывести произвольный текст использовав функцию @code{SetTicksVal()}. +В цветовой схеме можно использовать тональные (``подсвеченные'') цвета. Тональный цвет задается двумя символами в фигурных скобках @samp{@{cN@}: первый -- обычный цвет, второй -- его яркость цифрой. Цифра может быть в диапазоне @samp{1}...@samp{9}. При этом @samp{5} соответствует нормальному цвету, @samp{1} -- очень темная версия цвета (почти черный), @samp{9} -- очень светлая версия цвета (почти белый). Например, цвета могут быть @samp{@{b2@}} @samp{@{b7@}} @samp{@{r7@}} и т.д. @c ------------------------------------------------------------------ -@node Line styles, Color scheme, Coordinate axes, General concepts -@subsection Стиль линий +@external +@node Line styles, Color scheme, Color styles, General concepts +@section Стиль линий @cindex Стиль линий @cindex Стиль маркеров @@ -25,70 +75,49 @@ @html По умолчанию палитры содержит следующие цвета: темно серыйH’, синийb’, зеленыйg’, красныйr’, голубойc’, пурпурныйm’, yellowy’, серыйh’, сине-зеленыйl’, небесно-синийn’, оранжевыйq’, желто-зеленыйe’, сине-фиолетовыйu’, фиолетовыйp’. -

Символы цвета: ‘k’ -- черный, ‘r’ -- красный, ‘R’ -- темно красный, ‘g’ -- зеленый, ‘G’ -- темно зеленый, ‘b’ -- синий, ‘B’ -- темно синий, ‘c’ -- голубой, ‘C’ -- темно голубой, ‘m’ -- пурпурный, ‘M’ -- темно пурпурный, ‘y’ -- желтый, ‘Y’ -- темно желтый (золотой), ‘h’ -- серый, ‘H’ -- темно серый, ‘w’ -- белый, ‘W’ -- светло серый, ‘l’ -- сине-зеленый, ‘L’ -- темно сине-зеленый, ‘e’ -- желто-зеленый, ‘E’ -- темно желто-зеленый, ‘n’ -- небесно-синий, ‘N’ -- темно небесно-синий, ‘u’ -- сине-фиолетовый, ‘U’ -- темно сине-фиолетовый, ‘p’ -- фиолетовый, ‘P’ -- темно фиолетовый, ‘q’ -- оранжевый, ‘Q’ -- темно оранжевый (коричневый).

- -Тип пунктира: пробел -- нет линии (для рисования только маркеров), ‘-’ -- сплошная линия (■■■■■■■■■■■■■■■■), ‘|’ -- длинный пунктир (■■■■■■■■□□□□□□□□), ‘;’ -- пунктир (■■■■□□□□■■■■□□□□), ‘=’ -- короткий пунктир (■■□□■■□□■■□□■■□□), ‘:’ -- точки (■□□□■□□□■□□□■□□□), ‘j’ -- пунктир с точками (■■■■■■■□□□□■□□□□), ‘i’ -- мелкий пунктир с точками (■■■□□■□□■■■□□■□□). +

Тип пунктира: пробел -- нет линии (для рисования только маркеров), ‘-’ -- сплошная линия (■■■■■■■■■■■■■■■■), ‘|’ -- длинный пунктир (■■■■■■■■□□□□□□□□), ‘;’ -- пунктир (■■■■□□□□■■■■□□□□), ‘=’ -- короткий пунктир (■■□□■■□□■■□□■■□□), ‘:’ -- точки (■□□□■□□□■□□□■□□□), ‘j’ -- пунктир с точками (■■■■■■■□□□□■□□□□), ‘i’ -- мелкий пунктир с точками (■■■□□■□□■■■□□■□□).

@end html @end ifhtml @ifnothtml -По умолчанию палитры содержит следующие цвета: темно серый @samp{H}, синий @samp{b}, зеленый @samp{g}, красный @samp{r}, голубой @samp{c}, пурпурный @samp{m}, yellow @samp{y}, серый @samp{h}, сине-зеленый @samp{l}, небесно-синий @samp{n}, оранжевый @samp{q}, желто-зеленый @samp{e}, сине-фиолетовый @samp{u}, фиолетовый @samp{p}. - -Символы цвета те же, что и в классе mglColor (@pxref{mglColor class}): @samp{k} -- черный, @samp{r} -- красный, @samp{R} -- темно красный, @samp{g} -- зеленый, @samp{G} -- темно зеленый, @samp{b} -- синий, @samp{B} -- темно синий, @samp{c} -- голубой, @samp{C} -- темно голубой, @samp{m} -- пурпурный, @samp{M} -- темно пурпурный, @samp{y} -- желтый, @samp{Y} -- темно желтый (золотой), @samp{h} -- серый, @samp{H} -- темно серый, @samp{w} -- белый, @samp{W} -- светло серый, @samp{l} -- сине-зеленый, @samp{L} -- темно сине-зеленый, @samp{e} -- желто-зеленый, @samp{E} -- темно желто-зеленый, @samp{n} -- небесно-синий, @samp{N} -- темно небесно-синий, @samp{u} -- сине-фиолетовый, @samp{U} -- темно сине-фиолетовый, @samp{p} -- фиолетовый, @samp{P} -- темно фиолетовый, @samp{q} -- оранжевый, @samp{Q} -- темно оранжевый (коричневый). +По умолчанию палитра содержит следующие цвета: темно серый @samp{H}, синий @samp{b}, зеленый @samp{g}, красный @samp{r}, голубой @samp{c}, пурпурный @samp{m}, yellow @samp{y}, серый @samp{h}, сине-зеленый @samp{l}, небесно-синий @samp{n}, оранжевый @samp{q}, желто-зеленый @samp{e}, сине-фиолетовый @samp{u}, фиолетовый @samp{p}. Тип пунктира: пробел -- нет линии (для рисования только маркеров), @samp{-} -- сплошная линия (################), @samp{|} -- длинный пунктир (########________), @samp{;} -- пунктир (####____####____), @samp{=} -- короткий пунктир (##__##__##__##__), @samp{:} -- точки (#___#___#___#___), @samp{j} -- пунктир с точками (#######____#____), @samp{i} -- мелкий пунктир с точками (###__#__###__#__). @end ifnothtml Типы маркеров: @samp{o} -- окружность, @samp{+} -- крест, @samp{x} -- косой крест, @samp{s} - квадрат, @samp{d} - ромб, @samp{.} -- точка, @samp{^} -- треугольник вверх, @samp{v} -- треугольник вниз, @samp{<} -- треугольник влево, @samp{>} -- треугольник вправо, @samp{#*} -- знак Y, @samp{#+} -- крест в квадрате, @samp{#x} -- косой крест в квадрате, @samp{#.} -- точка в окружности. Если в строке присутствует символ @samp{#}, то используются символы с заполнением. -@float -@image{../png/sample5, 7cm} -@caption{Стили линий и маркеров.} -@end float - На конце и в начале линии можно выводить специальный символ (стрелку), если в строке указать один из символов: @samp{A} -- стрелка наружу, @samp{V} -- стрелка внутрь, @samp{I} -- поперечная черта, @samp{K} -- стрелка с чертой, @samp{T} -- треугольник, @samp{S} -- квадрат, @samp{D} -- ромб, @samp{O} -- круг, @samp{_} -- нет стрелки (по умолчанию). При этом действует следующее правило: первый символ определяет стрелку на конце линии, второй символ -- стрелку в начале линии. Например, @samp{r-A} -- красная сплошная линия со стрелкой на конце, @samp{b|AI} -- синий пунктир со стрелкой на конце и чертой вначале, @samp{_O} -- линия с текущим стилем и кружком вначале. Эти стили действуют и при построении графиков (например, @ref{1D plotting}). -@float -@image{../png/sampled, 7cm} -@caption{Стили стрелок.} -@end float +@pfig{style, Color and line styles.} @c ------------------------------------------------------------------ +@external @node Color scheme, Font styles, Line styles, General concepts -@subsection Цветовая схема +@section Цветовая схема @cindex Цветовая схема -Цветовая схема используется для определения цвета поверхностей, линий уровня и пр. Цветовая схема задается строкой @emph{s}, которая содержит символы цвета (@pxref{Line styles}) или символы @samp{d#:|}. Символ @samp{d} указывает на определение цвета в зависимости от положения точки в пространстве, а не по амплитуде данных. Символ @samp{#} переключает рисование поверхности на сетчатое (для трехмерных поверхностей) или включает рисование сетки на поверхности. Символ @samp{|} отключает интерполяцию цвета в цветовой схеме. Это может быть полезно для ``резких'' цветов, например, при рисовании матриц. Если в строке встречается символ @samp{:}, то он принудительно заканчивает разбор строки для стиля поверхности. После этого символа могут идти описание стиля текста или оси вращения кривой/линий уровня. Цветовая схема может содержать до 32 значений цвета. - -В цветовой схеме можно использовать тональные (``подсвеченные'') цвета (@emph{не в стиле линий!}). Тональный цвет задается двумя символами: первый -- обычный цвет, второй -- его яркость цифрой. Цифра может быть в диапазоне @samp{1}...@samp{9}. При этом @samp{5} соответствует нормальному цвету, @samp{1} -- очень темная версия цвета (почти черный), @samp{9} -- очень светлая версия цвета (почти белый). Например цветовая схема может быть @samp{b2b7wr7r2}. +Цветовая схема используется для определения цвета поверхностей, линий уровня и пр. Цветовая схема задается строкой @emph{s}, которая содержит символы цвета (@pxref{Line styles}) или символы @samp{#:|}. Символ @samp{#} переключает рисование поверхности на сетчатое (для трехмерных поверхностей) или включает рисование сетки на поверхности. Символ @samp{|} отключает интерполяцию цвета в цветовой схеме. Это может быть полезно для ``резких'' цветов, например, при рисовании матриц. Если в строке встречается символ @samp{:}, то он принудительно заканчивает разбор строки для стиля поверхности. После этого символа могут идти описание стиля текста или оси вращения кривой/линий уровня. Цветовая схема может содержать до 32 значений цвета. -@float -@image{../png/colors, 7cm} -@caption{Цвета и их идентификаторы.} -@end float - -При определении цвета по @emph{амплитуде} (наиболее часто используется) окончательный цвет определяется путем линейной интерполяции массива цветов. Массив цветов формируется из цветов, указанных в строке спецификации. Аргумент -- амплитуда, нормированная между @var{Cmin} -- @var{Cmax} (@pxref{Axis settings}). Например, строка из 4 символов @samp{bcyr} соответствует изменению цвета от синего (минимальное значение) через голубой и желтый (промежуточные значения) к красному (максимальное значение). Строка @samp{kw} соответствует изменению цвета от черного (минимальное значение) к белому (максимальное значение). Строка из одного символа (например, @samp{g}) соответствует однотонному цвету (в данному случае зеленому). +При определении цвета по @emph{амплитуде} (наиболее часто используется) окончательный цвет определяется путем линейной интерполяции массива цветов. Массив цветов формируется из цветов, указанных в строке спецификации. Аргумент -- амплитуда, нормированная между @var{Cmin} -- @var{Cmax} (см. @ref{Axis settings}). Например, строка из 4 символов @samp{bcyr} соответствует изменению цвета от синего (минимальное значение) через голубой и желтый (промежуточные значения) к красному (максимальное значение). Строка @samp{kw} соответствует изменению цвета от черного (минимальное значение) к белому (максимальное значение). Строка из одного символа (например, @samp{g}) соответствует однотонному цвету (в данному случае зеленому). Есть несколько полезных цветовых схем. Строка @samp{kw} дает обычную серую (черно-белую) схему, когда большие значения светлее. Строка @samp{wk} представляет обратную серую схему, когда большие значения темнее. Строки @samp{kRryw}, @samp{kGgw}, @samp{kBbcw} представляют собой хорошо известные схемы @emph{hot}, @emph{summer} и @emph{winter}. Строки @samp{BbwrR} и @samp{bBkRr} позволяют рисовать двухцветные фигуры на белом или черном фоне, когда отрицательные значения показаны синим цветом, а положительные -- красным. Строка @samp{BbcyrR} дает цветовую схему, близкую к хорошо известной схеме @emph{jet}. +@pfig{schemes, Most popular color schemes.} -@float -@image{../png/color_schemes, 7cm} -@caption{Наиболее популярные цветовые схемы.} -@end float - -При определении цвета по @emph{положению точки в пространстве} окончательный цвет определяется по формуле c=x*c[1] + y*c[2] + z*c[3]. Здесь c[1], c[2], c[3] -- первые три цвета в цветовом массиве; x, y, z -- координаты точки, нормированные на @var{Min}x@var{Max}. Такой тип определения цвета полезен, например, при построении поверхностей уровня, когда цвет дает представление о положении точки в пространстве. +При определении цвета по @emph{положению точки в пространстве} (используется в @ref{map}) окончательный цвет определяется по формуле c=x*c[1] + y*c[2]. Здесь c[1], c[2] -- первые три цвета в цветовом массиве; x, y -- координаты точки, нормированные на @var{Min}x@var{Max}. +@c Такой тип определения цвета полезен, например, при построении поверхностей уровня, когда цвет дает представление о положении точки в пространстве. @c ------------------------------------------------------------------ +@external @node Font styles, Textual formulas, Color scheme, General concepts -@subsection Стиль текста +@section Стиль текста @cindex Стиль текста -Стиль текста задается строкой, которая может содержать несколько символов: тип шрифта (@samp{ribwou}) и/или выравнивания (@samp{LRC}), а также цвет текста @samp{wkrgbcymhRGBCYMHW} (@pxref{Line styles}) после символа @samp{:}. Например, @samp{r:iCb} соответствует жирному курсиву с выравниванием по центру красного цвета. +Стиль текста задается строкой, которая может содержать цвет текста @samp{wkrgbcymhRGBCYMHW} (см. @ref{Color styles}), а также тип шрифта (@samp{ribwou}) и/или выравнивания (@samp{LRC}) после символа @samp{:}. Например, @samp{r:iCb} соответствует жирному (@samp{b}) курсиву (@samp{i}) с выравниванием по центру (@samp{C} красного цвета (@samp{r}). -Начертания шрифта: @samp{r} -- прямой шрифт, @samp{i} -- курсив, @samp{b} -- жирный. По умолчанию используется прямой шрифт. Типы выравнивания текста: @samp{L} -- по левому краю (по умолчанию), @samp{C} -- по центру, @samp{R} -- по правому краю. Дополнительные эффекты шрифта: @samp{w} -- контурный, @samp{o} -- надчеркнутый, @samp{u} -- подчеркнутый. -@c Синтаксический разбор LaTeX-их команд по умолчанию включен (подробнее см. @pxref{mglFont class} и @ref{Font settings}). +Начертания шрифта: @samp{r} -- прямой шрифт, @samp{i} -- курсив, @samp{b} -- жирный. По умолчанию используется прямой шрифт. Типы выравнивания текста: @samp{L} -- по левому краю (по умолчанию), @samp{C} -- по центру, @samp{R} -- по правому краю. Дополнительные эффекты шрифта: @samp{w} -- контурный, @samp{o} -- надчеркнутый, @samp{u} -- подчеркнутый. Синтаксический разбор LaTeX-их команд по умолчанию включен. Это команды смены стиля текста (например, \b для жирного текста): \a или \overline -- надчеркивание, \b или \textbf -- жирный, \i или \textit -- курсив, \r или \textrm -- прямой (отменяет стили жирного и курсива), \u или \underline -- подчеркнутый, \w или \wire -- контурный, \big -- большего размера, @@ -- меньшего размера. Нижний и верхний индексы задаются символами @samp{_} и @samp{^}. При этом изменение стиля применяется только к следующему символу или к символам в фигурных скобках @{@}, которые понимаются как единый блок. Например, сравните строки @samp{sin (x^@{2^3@})} и @samp{sin (x^2^3)}. Можно также менять цвет текста внутри строки с помощью команд #? или \color?, где @samp{?} -- символ цвета (@pxref{Line styles}). Например, слова @samp{Blue} и @samp{red} будут окрашены в соответствующий цвет в строке @samp{#b@{Blue@} and \colorr@{red@} text}. Большинство функций понимает символ новой строки @samp{\n} и позволяет выводить много строчный текст. Наконец, можно использовать символы с произвольным UTF кодом с помощью команды @code{\utf0x????}. Например, @code{\utf0x3b1} даст символ @ifhtml @@ -107,7 +136,7 @@ В частности, распознаются греческие буквы: α – \alpha, β – \beta, γ – \gamma, δ – \delta, ε – \epsilon, η – \eta, ι – \iota, χ – \chi, κ – \kappa, λ – \lambda, μ – \mu, ν – \nu, o – \o, ω – \omega, ϕ – \phi, π – \pi, ψ – \psi, ρ – \rho, σ – \sigma, θ – \theta, τ – \tau, υ – \upsilon, ξ – \xi, ζ – \zeta, ς – \varsigma, ɛ – \varepsilon, ϑ – \vartheta, φ – \varphi, ϰ – \varkappa; A – \Alpha, B – \Beta, Γ – \Gamma, Δ – \Delta, E – \Epsilon, H – \Eta, I – \Iota, C – \Chi, K – \Kappa, Λ – \Lambda, M – \Mu, N – \Nu, O – \O, Ω – \Omega, Φ – \Phi, Π – \Pi, Ψ – \Psi, R – \Rho, Σ – \Sigma, Θ – \Theta, T – \Tau, Υ – \Upsilon, Ξ – \Xi, Z – \Zeta.

Еще примеры наиболее общеупотребительных TeX-их символов: ∠ – \angle, ⋅ – \cdot, ♣ – \clubsuit, ✓ – \checkmark, ∪ – \cup, ∩ – \cap, ♢ – \diamondsuit, ◇ – \diamond, ÷ - – \div, + – \div, ↓ – \downarrow, † – \dag, ‡ – \ddag, ≡ – \equiv, ∃ – \exists, ⌢ – \frown, ♭ – \flat, ≥ – \ge, ≥ – \geq, ≧ – \geqq, ← – \gets, ♡ – \heartsuit, ∞ – \infty, ∫ – \int, \Int, ℑ – \Im, ♢ – \lozenge, ⟨ – \langle, ≤ – \le, ≤ – \leq, ≦ – \leqq, ← – \leftarrow, ∓ – \mp, ∇ – \nabla, ≠ – \ne, ≠ – \neq, ♮ – \natural, ∮ – \oint, ⊙ – \odot, ⊕ – \oplus, ∂ – \partial, ∥ – \parallel, ⊥ –\perp, ± – \pm, ∝ – \propto, ∏ – \prod, ℜ – \Re, → – \rightarrow, ⟩ – \rangle, ♠ – \spadesuit, ~ – \sim, ⌣ – \smile, ⊂ – \subset, ⊃ – \supset, √ – \sqrt or \surd, § – \S, ♯ – \sharp, ∑ – \sum, × – \times, → – \to, ∴ – \therefore, ↑ – \uparrow, ℘ – \wp.

@end html @end ifhtml @@ -120,14 +149,15 @@ Размер текста может быть задан явно (если @var{size}>0) или относительно базового размера шрифта для рисунка |@var{size}|*@var{FontSize} при @var{size}<0. Значение @var{size}=0 указывает, что соответствующая строка выводиться не будет. Базовый размер шрифта измеряется во внутренних единицах. Специальные функции @code{SetFontSizePT(), SetFontSizeCM(), SetFontSizeIN()} позволяют задавать его в более ``привычных'' единицах. @c ------------------------------------------------------------------ +@external @node Textual formulas, Command options, Font styles, General concepts -@subsection Текстовые формулы +@section Текстовые формулы @cindex Текстовые формулы MathGL имеет быстрый парсер текстовых формул @ifclear UDAV - (@pxref{mglFormula class}) +(@pxref{Evaluate expression}) @end ifclear , понимающий большое число функций и операций. Базовые операции: @samp{+} -- сложение, @samp{-} -- вычитание, @samp{*} -- умножение, @samp{/} -- деление, @samp{^} -- возведение в целосичленную степень. Также есть логические операции: @samp{<} -- истина если if x} -- истина если x>y, @samp{=} -- истина если x=y, @samp{&} -- истина если x и y оба не равны нулю, @samp{|} -- истина если x или y не нуль. Логические операции имеют наинизший приоритет и возвращают 1 если истина или 0 если ложно. @@ -166,14 +196,13 @@ MathGL имеет быстрый парсер текстовых формул Функции Якоби: @samp{sn(u,m)}, @samp{cn(u,m)}, @samp{dn(u,m)}, @samp{sc(u,m)}, @samp{sd(u,m)}, @samp{ns(u,m)}, @samp{cs(u,m)}, @samp{cd(u,m)}, @samp{nc(u,m)}, @samp{ds(u,m)}, @samp{dc(u,m)}, @samp{nd(u,m)}. -Некоторые из функций могут быть недоступны если флаг NO_GSL был определен при компиляции библиотеки MathGL. +Некоторые из функций могут быть недоступны если не была включена поддержка GSL при компиляции библиотеки MathGL. При разборе формул нет различия между верхним и нижним регистром. Если аргумент лежит вне области определения функции, то возвращается NaN. @c ------------------------------------------------------------------ -@node Command options, , Textual formulas, General concepts -@section Command options - +@external +@node Command options, Interfaces, Textual formulas, General concepts @section Опции команд Опции команд позволяют легко настроить вид отдельного графика не меняя глобальных настроек для все рисунка. Каждая опция отделяется от предыдущей символом @samp{;}. Опции работают так, что запоминают текущие настройки рисунка, применяют собственные настройки, выполняют команду и возвращают глобальные настройки обратно. Поэтому использование опций для команд обработки данных или настройки графика бесполезно. @@ -184,17 +213,17 @@ MathGL имеет быстрый парсер текстовых формул @cindex alpha @cindex alphadef @deffn {Опция MGL} alpha @code{val} -@deffnx {Опция MGL} alphadef @code{val} Задает величину прозрачности поверхности. Значение должно быть в диапазоне [0, 1]. См. также @ref{alphadef} @end deffn @cindex ambient @deffn {Опция MGL} ambient @code{val} Задает яркость фонового освещения. Значение должно быть в диапазоне [0, 1]. См. также @ref{ambient} @end deffn -@cindex crange -@deffn {Опция MGL} crange @code{val1 val2} -Задает границы цветовой шкалы. См. также @ref{crange} +@cindex diffuse +@deffn {Опция MGL} diffuse @code{val} +Задает яркость диффузного освещения для поверхности. Значение должно быть в диапазоне [0, 1]. См. также @ref{diffuse}. @end deffn + @cindex xrange @deffn {Опция MGL} xrange @code{val1 val2} Задает границы изменения координаты x. См. также @ref{xrange} @@ -207,22 +236,20 @@ MathGL имеет быстрый парсер текстовых формул @deffn {Опция MGL} zrange @code{val1 val2} Задает границы изменения координаты z. См. также @ref{zrange} @end deffn + @cindex cut @deffn {Опция MGL} cut @code{val} -Задает обрезание точек за пределами осей координат. См. также @ref{cut} +Задает обрезание точек за пределами осей координат. См. также @ref{cut}. @end deffn @cindex fontsize -@deffn {Опция MGL} fontsize @code{val} -Задает размер текста. См. также @ref{font} -@end deffn -@cindex marksize -@deffn {Опция MGL} marksize @code{val} -Задает размер маркеров. См. также @ref{marksize} +@deffn {Опция MGL} size @code{val} +Задает размер текста, маркеров и стрелок. См. также @ref{font}, @ref{marksize}, @ref{arrowsize}. @end deffn @cindex meshnum @deffn {Опция MGL} meshnum @code{val} Задает ориентировочное число линий, стрелок, ячеек и пр. См. также @ref{meshnum} @end deffn + @cindex legend @deffn {Опция MGL} legend 'txt' Добавляет строку 'txt' во внутренний массив записей легенды. Стиль линии и маркера аргумента последней вызванной команды построения @ref{1D plotting}. См. также @ref{legend} @@ -231,3 +258,86 @@ MathGL имеет быстрый парсер текстовых формул @deffn {MGL option} value @code{val} Задает значение, которое будет использовано как дополнительный числовой параметр при построении графика. @end deffn + + + +@c ------------------------------------------------------------------ +@external +@node Interfaces, , Command options, General concepts +@section Интерфейсы + +@c TODO Translate it!!! + +@ifset UDAV +You can use @code{mglParse} class for executing MGL scripts from different languages. +@end ifset + +@ifclear UDAV + +The MathGL library has interfaces for a set of languages. Most of them are based on the C interface via SWIG tool. There are Python, Java, Octave, Lisp, C#, Guile, Lua, Modula 3, Ocaml, Perl, PHP, Pike, R, Ruby, and Tcl interfaces. Also there is a Fortran interface which has a similar set of functions, but slightly different types of arguments (integers instead of pointers). These functions are marked as [C function]. + +Some of the languages listed above support classes (like C++ or Python). The name of functions for them is the same as in C++ (see @ref{MathGL core} and @ref{Data processing}) and marked like [Method on mglGraph]. + +Finally, a special command language MGL (see @ref{MGL scripts}) was written for a faster access to plotting functions. Corresponding scripts can be executed separately (by UDAV, mglconv, mglview and so on) or from the C/C++/Python/... code (@pxref{mglParse class}). + +@menu +* C interface:: +* C++ interface:: +@end menu + +@external +@node C interface, C++ interface, , Interfaces +@subsection C/Fortran interface + +The C interface is a base for many other interfaces. It contains the pure C functions for most of the methods of MathGL classes. In distinction to C++ classes, C functions must have an argument HMGL (for graphics) and/or HMDT (for data arrays), which specifies the object for drawing or manipulating (changing). So, firstly, the user has to create this object by the function @code{mgl_create_*()} and has to delete it after the use by function @code{mgl_delete_*()}. + +All C functions are described in the header file @code{#include } and use variables of the following types: +@itemize +@item +@code{HMGL} --- Pointer to class @code{mglGraph} (@pxref{MathGL core}). +@item +@code{HMDT} --- Pointer to class @code{mglData} (@pxref{Data processing}). +@item +@code{HMPR} --- Pointer to class @code{mglParse} (@pxref{mglParse class}). +@end itemize +These variables contain identifiers for graphics drawing objects and for the data objects. + +Fortran functions/subroutines have the same names as C functions. However, there is a difference. Variable of type @code{HMGL, HMDT} must be an integer with sufficient size (@code{integer*4} in the 32-bit operating system or @code{integer*8} in the 64-bit operating system). All C functions are subroutines in Fortran, which are called by operator @code{call}. The exceptions are functions, which return variables of types @code{HMGL} or @code{HMDT}. These functions should be declared as integer in Fortran code. Also, one should keep in mind that strings in Fortran are denoted by @code{'} symbol, not the @code{"} symbol. + +@external +@node C++ interface, , C interface, Interfaces +@subsection C++/Python interface + +MathGL provides the interface to a set of languages via SWIG library. Some of these languages support classes. The typical example is Python -- which is named in this chapter's title. Exactly the same classes are used for high-level C++ API. Its feature is using only inline member-functions what make high-level API to be independent on compiler even for binary build. + +There are 3 classes in: +@itemize +@item @code{mglGraph} +-- provide most plotting functions (see @ref{MathGL core}). +@item @code{mglData} +-- provide base data processing (see @ref{Data processing}). It have an additional feature to access data values. You can use a construct like this: @code{dat[i]=sth;} or @code{sth=dat[i]} where flat representation of data is used (i.e., @var{i} can be in range 0...nx*nx*nz-1). You can also import NumPy arrays as input arguments in Python: @code{mgl_dat = mglData(numpy_dat);}. +@item @code{mglParse} +-- provide functions for parsing MGL scripts (see @ref{MGL scripts}). +@end itemize + + +To use Python classes just execute @samp{import mathgl}. The simplest example will be: +@verbatim +import mathgl +a=mathgl.mglGraph() +a.Box() +a.WritePNG("test.png") +@end verbatim +Alternatively you can import all classes from @code{mathgl} module and easily access MathGL classes like this: +@verbatim +from mathgl import * +a=mglGraph() +a.Box() +a.WritePNG("test.png") +@end verbatim +This becomes useful if you create many @code{mglData} objects, for example. + +@end ifclear + +@external + diff --git a/texinfo/core_en.texi b/texinfo/core_en.texi index 1869640..a4e6c40 100644 --- a/texinfo/core_en.texi +++ b/texinfo/core_en.texi @@ -28,10 +28,11 @@ The core of MathGL is @strong{mglGraph} class defined in @code{#include