initial upload
This commit is contained in:
parent
59390f54bf
commit
b425fe89af
37
.gitignore
vendored
37
.gitignore
vendored
@ -1,34 +1,3 @@
|
||||
# ---> C++
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
.DS_Store
|
||||
build/
|
||||
.vscode/
|
40
CMakeLists.txt
Normal file
40
CMakeLists.txt
Normal file
@ -0,0 +1,40 @@
|
||||
cmake_minimum_required(VERSION 3.15.2)
|
||||
# 设置项目名称与语言
|
||||
project(GCTL_GRAPHIC VERSION 1.0)
|
||||
# 添加配置配件编写的函数
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
option(GCTL_GRAPHIC_GMT "Use the GMT library" ON)
|
||||
option(GCTL_GRAPHIC_MATHGL "Use the MathGL2 library" ON)
|
||||
|
||||
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
|
||||
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
|
||||
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
||||
message(STATUS "[GCTL_GRAPHIC] Use the GMT library: " ${GCTL_GRAPHIC_GMT})
|
||||
message(STATUS "[GCTL_GRAPHIC] Use the MathGL2 library: " ${GCTL_GRAPHIC_MATHGL})
|
||||
|
||||
find_package(GCTL REQUIRED)
|
||||
message(STATUS "Found GCTL")
|
||||
include_directories(${GCTL_INC_DIR})
|
||||
|
||||
if(GCTL_GRAPHIC_GMT)
|
||||
find_package(GMT REQUIRED)
|
||||
message(STATUS "Found GMT")
|
||||
include_directories(${GMT_INC_DIR})
|
||||
endif()
|
||||
|
||||
if(GCTL_GRAPHIC_MATHGL)
|
||||
find_package(MathGL2 REQUIRED FLTK)
|
||||
message(STATUS "MathGL2 Version: " ${MathGL2_VERSION})
|
||||
include_directories(${MathGL2_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
# 加入一个头文件配置,让cmake对源码进行操作
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/config.h.in"
|
||||
"${PROJECT_SOURCE_DIR}/lib/graphic/gctl_graphic_config.h"
|
||||
)
|
||||
|
||||
# 添加库源文件地址
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(example)
|
41
GCTL_GRAPHICConfig.cmake.in
Normal file
41
GCTL_GRAPHICConfig.cmake.in
Normal file
@ -0,0 +1,41 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set(@PROJECT_NAME@_VERSION "@PROJECT_VERSION@")
|
||||
set_and_check(@PROJECT_NAME@_INSTALL_PREFIX "${PACKAGE_PREFIX_DIR}")
|
||||
set_and_check(@PROJECT_NAME@_INC_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
|
||||
set_and_check(@PROJECT_NAME@_LIB_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||
set_and_check(@PROJECT_NAME@_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib")
|
||||
|
||||
set(@PROJECT_NAME@_LIB gctl_graphic)
|
||||
set(@PROJECT_NAME@_LIBRARY gctl_graphic)
|
||||
|
||||
set(@PROJECT_NAME@_GMT @GCTL_GRAPHIC_GMT@)
|
||||
set(@PROJECT_NAME@_MATHGL @GCTL_GRAPHIC_MATHGL@)
|
||||
|
||||
message(STATUS "[GCTL_GRAPHIC] Use the GMT library: " @GCTL_GRAPHIC_GMT@)
|
||||
message(STATUS "[GCTL_GRAPHIC] Use the mathGL library: " @GCTL_GRAPHIC_MATHGL@)
|
||||
|
||||
if(NOT GCTL_FOUND)
|
||||
find_package(GCTL REQUIRED)
|
||||
include_directories(${GCTL_INC_DIR})
|
||||
endif()
|
||||
|
||||
if(@PROJECT_NAME@_GMT)
|
||||
if(NOT GMT_FOUND)
|
||||
find_package(GMT REQUIRED)
|
||||
include_directories(${GMT_INC_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(@PROJECT_NAME@_MATHGL)
|
||||
if(NOT MathGL2_FOUND)
|
||||
find_package(MathGL2 REQUIRED FLTK)
|
||||
include_directories(${MathGL2_INCLUDE_DIRS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# include target information
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
|
||||
check_required_components(@PROJECT_NAME@)
|
2
config.h.in
Normal file
2
config.h.in
Normal file
@ -0,0 +1,2 @@
|
||||
#cmakedefine GCTL_GRAPHIC_GMT
|
||||
#cmakedefine GCTL_GRAPHIC_MATHGL
|
23
doc/GMT/GMTConfig.cmake
Normal file
23
doc/GMT/GMTConfig.cmake
Normal file
@ -0,0 +1,23 @@
|
||||
macro(set_and_check _var _file)
|
||||
set(${_var} "${_file}")
|
||||
if(NOT EXISTS "${_file}")
|
||||
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# change the following options as needed
|
||||
set(GMT_VERSION "6.0.0")
|
||||
|
||||
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
|
||||
set_and_check(GMT_INC_DIR "/opt/homebrew/include")
|
||||
set_and_check(GMT_LIB_DIR "/opt/homebrew/lib")
|
||||
|
||||
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
|
||||
set_and_check(GMT_INC_DIR "/usr/include")
|
||||
set_and_check(GMT_LIB_DIR "/usr/lib/x86_64-linux-gnu")
|
||||
|
||||
else()
|
||||
message(FATAL_ERROR "Unset operation system for GMT. Please edit the GMTConfig.cmake file.")
|
||||
endif()
|
||||
|
||||
set(GMT_LIB gmt)
|
23
example/CMakeLists.txt
Normal file
23
example/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
macro(add_example name switch)
|
||||
if(${switch})
|
||||
# 添加可执行程序名称
|
||||
add_executable(${name} ${name}.cpp)
|
||||
# 设置安装后的动态库调用地址
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
target_link_libraries(${name} PRIVATE ${GCTL_LIB})
|
||||
target_link_libraries(${name} PRIVATE gctl_graphic)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
if(${GCTL_GRAPHIC_GMT})
|
||||
add_example(JX_single_ex ON)
|
||||
endif()
|
||||
|
||||
if(${GCTL_GRAPHIC_MATHGL})
|
||||
add_example(mathgl_plot_ex ON)
|
||||
add_example(mathgl_dens_ex ON)
|
||||
endif()
|
49
example/JX_single_ex.cpp
Normal file
49
example/JX_single_ex.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/graphic.h"
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<double> data(51*41);
|
||||
|
||||
double dist;
|
||||
for (int i = 0; i < 51; ++i)
|
||||
{
|
||||
for (int j = 0; j < 41; ++j)
|
||||
{
|
||||
dist = sqrt((j-20)*(j-20) + (i-25)*(i-25));
|
||||
data[j+i*41] = sin(dist/GCTL_Pi);
|
||||
}
|
||||
}
|
||||
|
||||
gctl::gmt_JX_single pic;
|
||||
pic.show_command();
|
||||
pic.set_command("psconvert", "-A -TG -E300");
|
||||
pic.plot("gmt_plot_ex", data, 0, 40, 0, 50, 41, 51);
|
||||
return 0;
|
||||
}
|
53
example/mathgl_dens_ex.cpp
Normal file
53
example/mathgl_dens_ex.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/graphic.h"
|
||||
|
||||
#define NUM 101
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<double> x(NUM), y(NUM), z(NUM*NUM);
|
||||
gctl::sequence(x, -2.0*GCTL_Pi, 0.04*GCTL_Pi);
|
||||
gctl::sequence(y, -2.0*GCTL_Pi, 0.04*GCTL_Pi);
|
||||
|
||||
for (size_t i = 0; i < NUM; i++)
|
||||
{
|
||||
for (size_t j = 0; j < NUM; j++)
|
||||
{
|
||||
z[j + i*NUM] = sin(sqrt(x[j]*x[j] + y[i]*y[i]));
|
||||
}
|
||||
}
|
||||
|
||||
gctl::mathgl_dens plt;
|
||||
plt.range(-2.0*GCTL_Pi, 2.0*GCTL_Pi, -2.0*GCTL_Pi, 2.0*GCTL_Pi);
|
||||
plt.demension(NUM, NUM);
|
||||
plt.add_dens(z, "sin");
|
||||
plt.plot();
|
||||
|
||||
return 0;
|
||||
}
|
48
example/mathgl_plot_ex.cpp
Normal file
48
example/mathgl_plot_ex.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "../lib/graphic.h"
|
||||
|
||||
#define NUM 101
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
gctl::array<double> x(NUM), y(NUM);
|
||||
|
||||
gctl::sequence(x, -2.0*GCTL_Pi, 0.04*GCTL_Pi);
|
||||
for (size_t i = 0; i < NUM; i++)
|
||||
{
|
||||
y[i] = sin(x[i]);
|
||||
}
|
||||
|
||||
gctl::mathgl_plot plt;
|
||||
plt.init_axis(x, "time (s)");
|
||||
plt.add_profile(y, "single (db)");
|
||||
plt.plot();
|
||||
|
||||
return 0;
|
||||
}
|
54
installer
Executable file
54
installer
Executable file
@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $# == 0 || ${1} == "help" ]]; then
|
||||
echo "Compiles executables/libraries and maintains installed files. Two tools 'Cmake' and 'stow' are empolyed here. For more information, see https://cmake.org and https://www.gnu.org/software/stow/."
|
||||
echo ""
|
||||
echo "School of Earth Sciences, Zhejiang University"
|
||||
echo "Yi Zhang (yizhang-geo@zju.edu.cn)"
|
||||
echo ""
|
||||
echo "Usage: ./config.sh [option] [Cmake options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo "(1) configure: Configure Cmake project(s). This option could take extra Cmake options as in <option>=<value>."
|
||||
echo "(2) build: Build executables/libraries."
|
||||
echo "(3) install: Install executables/libraries to the directory of CMAKE_INSTALL_PREFIX and sym-links them to the target address. This offers a quick and clean remove of the installed files."
|
||||
echo "(4) clean: Clean build/ folder(s)."
|
||||
echo "(5) uninstall: Delete the installed files and sym-links."
|
||||
echo "(6) info: Print out current setups."
|
||||
echo "(7) help: Show help information."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
package=gctl_graphic
|
||||
address=/opt/stow
|
||||
taress=/usr/local
|
||||
option="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${address}/${package}"
|
||||
|
||||
if [[ $# -gt 1 ]]; then
|
||||
for opt in "$@"; do
|
||||
if [[ ${opt} != "configure" ]]; then
|
||||
option="${option} -D${opt}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${1} == "configure" && ! -d "build/" ]]; then
|
||||
mkdir build && cd build && cmake .. ${option}
|
||||
elif [[ ${1} == "configure" ]]; then
|
||||
cd build && rm -rf * && cmake .. ${option}
|
||||
elif [[ ${1} == "build" ]]; then
|
||||
cd build && make
|
||||
elif [[ ${1} == "install" ]]; then
|
||||
cd build && sudo make install
|
||||
sudo stow --dir=${address} --target=${taress} -S ${package}
|
||||
elif [[ ${1} == "clean" ]]; then
|
||||
rm -rf build/
|
||||
elif [[ ${1} == "uninstall" ]]; then
|
||||
sudo stow --dir=${address} --target=${taress} -D ${package}
|
||||
sudo rm -rf ${address}/${package}
|
||||
elif [[ ${1} == "info" ]]; then
|
||||
echo "package name:" ${package}
|
||||
echo "stow address:" ${address}
|
||||
echo "target address:" ${taress}
|
||||
echo "Cmake options:" ${option}
|
||||
fi
|
78
lib/CMakeLists.txt
Normal file
78
lib/CMakeLists.txt
Normal file
@ -0,0 +1,78 @@
|
||||
# 设置编译选项
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -O3")
|
||||
# 设置库文件的输出地址
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||
|
||||
# 设定库源文件文件夹
|
||||
aux_source_directory(graphic/ GCTL_GRAPHIC_SRC)
|
||||
|
||||
# 以下部分为库的编译
|
||||
# 注意目标名必须唯一 所以不能直接生成相同名称的动态库与静态库
|
||||
# 注意此处不必为目标名称添加lib前缀和相应后缀,cmake会自行添加
|
||||
add_library(gctl_graphic SHARED ${GCTL_GRAPHIC_SRC})
|
||||
# 首先添加静态库的生成命令
|
||||
add_library(gctl_graphic_static STATIC ${GCTL_GRAPHIC_SRC})
|
||||
# 设置静态库的输出名称从而获得与动态库名称相同的静态库
|
||||
set_target_properties(gctl_graphic_static PROPERTIES OUTPUT_NAME "gctl_graphic")
|
||||
# 设置输出目标属性以同时输出动态库与静态库
|
||||
set_target_properties(gctl_graphic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
set_target_properties(gctl_graphic_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
# 设置动态库的版本号
|
||||
set_target_properties(gctl_graphic PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
||||
# 设置动态库的运行搜索地址
|
||||
set_target_properties(gctl_graphic PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(gctl_graphic_static PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(gctl_graphic PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
set_target_properties(gctl_graphic_static PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
#连接动态库
|
||||
target_link_libraries(gctl_graphic PUBLIC ${GCTL_LIB})
|
||||
target_link_libraries(gctl_graphic_static ${GCTL_LIB})
|
||||
|
||||
if(GCTL_GRAPHIC_GMT)
|
||||
find_library(LIB_TAR ${GMT_LIB} HINTS ${GMT_LIB_DIR})
|
||||
target_link_libraries(gctl_graphic PUBLIC ${LIB_TAR})
|
||||
target_link_libraries(gctl_graphic_static ${LIB_TAR})
|
||||
endif()
|
||||
|
||||
if(GCTL_GRAPHIC_MATHGL)
|
||||
target_link_libraries(gctl_graphic PUBLIC ${MathGL2_LIBRARIES})
|
||||
target_link_libraries(gctl_graphic PUBLIC ${MathGL2_FLTK_LIBRARIES})
|
||||
target_link_libraries(gctl_graphic_static ${MathGL2_LIBRARIES})
|
||||
target_link_libraries(gctl_graphic_static ${MathGL2_FLTK_LIBRARIES})
|
||||
endif()
|
||||
|
||||
set(CONFIG_FILE_PATH lib/cmake/${PROJECT_NAME})
|
||||
|
||||
configure_package_config_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${CONFIG_FILE_PATH})
|
||||
|
||||
write_basic_package_version_file(${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
# 库的安装命令
|
||||
if(WIN32)
|
||||
install(TARGETS gctl_graphic DESTINATION lib)
|
||||
install(TARGETS gctl_graphic_static DESTINATION lib)
|
||||
else()
|
||||
install(TARGETS gctl_graphic gctl_graphic_static
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
install(EXPORT ${PROJECT_NAME}Targets
|
||||
DESTINATION ${CONFIG_FILE_PATH})
|
||||
install(FILES
|
||||
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
DESTINATION ${CONFIG_FILE_PATH})
|
||||
endif()
|
||||
|
||||
# 头文件安装命令
|
||||
file(GLOB GCTL_HEAD *.h)
|
||||
file(GLOB GCTL_GRAPHIC_HEAD graphic/*.h)
|
||||
|
||||
install(FILES ${GCTL_HEAD} DESTINATION include/gctl)
|
||||
install(FILES ${GCTL_GRAPHIC_HEAD} DESTINATION include/gctl/graphic)
|
35
lib/graphic.h
Normal file
35
lib/graphic.h
Normal file
@ -0,0 +1,35 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#ifndef _GCTL_GRAPHIC_H
|
||||
#define _GCTL_GRAPHIC_H
|
||||
|
||||
#include "graphic/gmt_JX_single.h"
|
||||
#include "graphic/mathgl_plot.h"
|
||||
#include "graphic/mathgl_dens.h"
|
||||
|
||||
#endif // _GCTL_GRAPHIC_H
|
2
lib/graphic/gctl_graphic_config.h
Normal file
2
lib/graphic/gctl_graphic_config.h
Normal file
@ -0,0 +1,2 @@
|
||||
#define GCTL_GRAPHIC_GMT
|
||||
#define GCTL_GRAPHIC_MATHGL
|
192
lib/graphic/gmt_JX_single.cpp
Normal file
192
lib/graphic/gmt_JX_single.cpp
Normal file
@ -0,0 +1,192 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "gmt_JX_single.h"
|
||||
|
||||
#ifdef GCTL_GRAPHIC_GMT
|
||||
|
||||
gctl::gmt_JX_single::gmt_JX_single()
|
||||
{
|
||||
name.resize(5);
|
||||
cmd.resize(5);
|
||||
|
||||
name[0] = "gmtset";
|
||||
cmd[0] = "FONT_ANNOT_PRIMARY=10.5p,Times-Roman,black \
|
||||
MAP_FRAME_PEN=thinnest,black \
|
||||
MAP_GRID_PEN_PRIMARY=thinnest,black \
|
||||
MAP_TICK_PEN_PRIMARY=thinnest,black \
|
||||
MAP_TICK_LENGTH_PRIMARY=1p/0.5p \
|
||||
MAP_TITLE_OFFSET=7.5p \
|
||||
MAP_GRID_CROSS_SIZE_PRIMARY=2p \
|
||||
FONT_LABEL=10.5p,Times-Roman,black \
|
||||
MAP_LABEL_OFFSET=5p \
|
||||
MAP_ANNOT_OFFSET_PRIMARY=2.5p";
|
||||
name[1] = "grd2cpt";
|
||||
cmd[1] = "-Crainbow -Z -D";
|
||||
name[2] = "grdimage";
|
||||
cmd[2] = "-Bxag+l\"x (m)\" -Byag+l\"y (m)\"";
|
||||
name[3] = "psscale";
|
||||
cmd[3] = "-Bxa -By+lm";
|
||||
name[4] = "psconvert";
|
||||
cmd[4] = "-A -TEG -E300";
|
||||
}
|
||||
|
||||
void gctl::gmt_JX_single::set_command(std::string in_name, std::string in_cmd)
|
||||
{
|
||||
for (int i = 0; i < name.size(); ++i)
|
||||
{
|
||||
if (name[i] == in_name)
|
||||
{
|
||||
cmd[i] = in_cmd;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void gctl::gmt_JX_single::show_command(std::ostream &out)
|
||||
{
|
||||
for (int i = 0; i < name.size(); ++i)
|
||||
{
|
||||
out << "Module: " << name[i] << " Command: " << cmd[i] << std::endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::string gctl::gmt_JX_single::get_command(std::string in_name)
|
||||
{
|
||||
for (int i = 0; i < name.size(); ++i)
|
||||
{
|
||||
if (name[i] == in_name)
|
||||
{
|
||||
return cmd[i];
|
||||
}
|
||||
}
|
||||
|
||||
throw runtime_error("No command found for module: "+in_name+". From gmt_JX_single::get_command(...)");
|
||||
}
|
||||
|
||||
void gctl::gmt_JX_single::plot(std::string plot_name, const array<double> &data, double xmin, double xmax, double ymin, double ymax, int xnum, int ynum)
|
||||
{
|
||||
std::string cpt_file = plot_name+".cpt";
|
||||
std::string ps_file = plot_name+".ps";
|
||||
|
||||
// Initiate a new GMT session
|
||||
// you need to destroy the session later
|
||||
void *API = GMT_Create_Session("gctl_gmt_plot", 2U, 0, NULL);
|
||||
|
||||
// prepare header info
|
||||
int m = xnum, n = ynum;
|
||||
double wesn[4] = {xmin, xmax, ymin, ymax};
|
||||
double inc[2] = {(xmax-xmin)/(xnum-1), (ymax-ymin)/(ynum-1)};
|
||||
// create an empty data container of GMT_GRID type
|
||||
// forcedly convert pointer type (C++ standard)
|
||||
// you need to destroy the data later
|
||||
struct GMT_GRID *G = reinterpret_cast<GMT_GRID*>(
|
||||
GMT_Create_Data(API, GMT_IS_GRID, GMT_IS_SURFACE,
|
||||
GMT_CONTAINER_AND_DATA, NULL, &wesn[0], &inc[0],
|
||||
GMT_GRID_NODE_REG, -1, NULL));
|
||||
|
||||
// manipulate grid data
|
||||
double *x_coord = GMT_Get_Coord(API, GMT_IS_GRID, GMT_X, G);
|
||||
double *y_coord = GMT_Get_Coord(API, GMT_IS_GRID, GMT_Y, G);
|
||||
|
||||
int idx;
|
||||
double minz = 1e+30, maxz = -1e+30;
|
||||
for (int i = 0; i < G->header->n_rows; i++)
|
||||
{
|
||||
for (int j = 0; j < G->header->n_columns; j++)
|
||||
{
|
||||
idx = GMT_Get_Index(API, G->header, i, j);
|
||||
G->data[idx] = data[j+(ynum-1-i)*xnum];
|
||||
|
||||
if (G->data[idx] < minz) minz = G->data[idx];
|
||||
if (G->data[idx] > maxz) maxz = G->data[idx];
|
||||
}
|
||||
}
|
||||
|
||||
G->header->z_min = minz;
|
||||
G->header->z_max = maxz;
|
||||
|
||||
// start the plotting
|
||||
// 1. set GMT defaults
|
||||
std::string args_defaults = get_command("gmtset");
|
||||
// call gmtset
|
||||
GMT_Call_Module (API, "gmtset", GMT_MODULE_CMD, (char*) args_defaults.c_str());
|
||||
|
||||
// load the grid to a virtual file for plotting
|
||||
char grid_name[GMT_VF_LEN] = {""};
|
||||
GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_IN, G, grid_name);
|
||||
// get string type of grid name
|
||||
std::string grid_name_str = grid_name;
|
||||
|
||||
// prepare cpt file
|
||||
std::string range_str = std::to_string(xmin)+"/"+std::to_string(xmax)+"/"+std::to_string(ymin)+"/"+std::to_string(ymax);
|
||||
std::string args_cpt = grid_name_str + " " + get_command("grd2cpt") + " -R" + range_str + " ->" + cpt_file;
|
||||
// call grd2cpt
|
||||
GMT_Call_Module (API, "grd2cpt", GMT_MODULE_CMD, (char*) args_cpt.c_str());
|
||||
|
||||
// plot the image
|
||||
std::string args_image = grid_name_str + " -R" + range_str + " -C" + cpt_file + " -JX1.5i/1.5i -X0.5i -Y0.5i --MAP_FRAME_AXES=WesNZ -K -P " + get_command("grdimage")
|
||||
+ " ->" + ps_file;
|
||||
// call grdimage
|
||||
GMT_Call_Module (API, "grdimage", GMT_MODULE_CMD, (char*) args_image.c_str());
|
||||
|
||||
// plot color bar
|
||||
std::string args_bar = get_command("psscale") + " -Dx0.1i/-0.2i+w1.3i/0.05i+h -C" + cpt_file + " -O -)" + ps_file;
|
||||
// call psscale
|
||||
GMT_Call_Module (API, "psscale", GMT_MODULE_CMD, (char*) args_bar.c_str());
|
||||
|
||||
// convert ps file to raster formats
|
||||
std::string args_pic = ps_file + " " + get_command("psconvert");
|
||||
// call psconvert
|
||||
GMT_Call_Module (API, "psconvert", GMT_MODULE_CMD, (char*) args_pic.c_str());
|
||||
|
||||
// close virtual file
|
||||
GMT_Close_VirtualFile (API, grid_name);
|
||||
|
||||
// destroy data container
|
||||
GMT_Destroy_Data(API, G);
|
||||
|
||||
// end the GMT session
|
||||
GMT_Destroy_Session(API);
|
||||
|
||||
// remove temporary files. including GMT defaults
|
||||
remove(cpt_file.c_str());
|
||||
remove(ps_file.c_str());
|
||||
// if exist, delete
|
||||
std::string hist_file = "gmt.history";
|
||||
std::string conf_file = "gmt.conf";
|
||||
if (!access(hist_file.c_str(), F_OK))
|
||||
remove(hist_file.c_str());
|
||||
if (!access(conf_file.c_str(), F_OK))
|
||||
remove(conf_file.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif // GCTL_GRAPHIC_GMT
|
64
lib/graphic/gmt_JX_single.h
Normal file
64
lib/graphic/gmt_JX_single.h
Normal file
@ -0,0 +1,64 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#ifndef _GCTL_JX_SINGLE_H
|
||||
#define _GCTL_JX_SINGLE_H
|
||||
|
||||
#include "gctl/core/array.h"
|
||||
#include "gctl/core/exceptions.h"
|
||||
|
||||
#include "gctl_graphic_config.h"
|
||||
#ifdef GCTL_GRAPHIC_GMT
|
||||
|
||||
#include "gmt/gmt.h"
|
||||
|
||||
#ifndef GMT_VF_LEN
|
||||
#define GMT_VF_LEN 16
|
||||
#endif
|
||||
|
||||
namespace gctl
|
||||
{
|
||||
class gmt_JX_single
|
||||
{
|
||||
public:
|
||||
gmt_JX_single();
|
||||
virtual ~gmt_JX_single(){}
|
||||
void set_command(std::string in_name, std::string in_cmd);
|
||||
void show_command(std::ostream &out = std::clog);
|
||||
void plot(std::string plot_name, const array<double> &data,
|
||||
double xmin, double xmax, double ymin, double ymax, int xnum, int ynum);
|
||||
|
||||
protected:
|
||||
std::string get_command(std::string in_name);
|
||||
std::vector<std::string> name;
|
||||
std::vector<std::string> cmd;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // GCTL_GRAPHIC_GMT
|
||||
|
||||
#endif // _GCTL_JX_SINGLE_H
|
120
lib/graphic/mathgl_dens.cpp
Normal file
120
lib/graphic/mathgl_dens.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "mathgl_dens.h"
|
||||
|
||||
#ifdef GCTL_GRAPHIC_MATHGL
|
||||
|
||||
gctl::mathgl_dens::mathgl_dens()
|
||||
{
|
||||
xnum_ = ynum_ = 0;
|
||||
x_ll_ = "x"; y_ll_ = "y"; z_ll_ = "z";
|
||||
}
|
||||
|
||||
gctl::mathgl_dens::~mathgl_dens(){}
|
||||
|
||||
void gctl::mathgl_dens::range(double xmin, double xmax, double ymin, double ymax)
|
||||
{
|
||||
xmin_ = xmin; xmax_ = xmax;
|
||||
ymin_ = ymin; ymax_ = ymax;
|
||||
return;
|
||||
}
|
||||
|
||||
void gctl::mathgl_dens::demension(int xnum, int ynum)
|
||||
{
|
||||
xnum_ = xnum; ynum_ = ynum;
|
||||
return;
|
||||
}
|
||||
|
||||
void gctl::mathgl_dens::xlabel(std::string xname)
|
||||
{
|
||||
x_ll_ = xname;
|
||||
return;
|
||||
}
|
||||
|
||||
void gctl::mathgl_dens::ylabel(std::string yname)
|
||||
{
|
||||
y_ll_ = yname;
|
||||
return;
|
||||
}
|
||||
|
||||
void gctl::mathgl_dens::add_dens(const array<double> &in_z, std::string z_label)
|
||||
{
|
||||
if (xnum_*ynum_ != in_z.size())
|
||||
throw std::runtime_error("[gctl::mathgl_dens] Invalid dens data size.");
|
||||
|
||||
z_ = in_z;
|
||||
z_ll_ = z_label;
|
||||
return;
|
||||
}
|
||||
|
||||
int gctl::mathgl_dens::Draw(mglGraph *gr)
|
||||
{
|
||||
mglData z_d;
|
||||
double zmin = z_[0], zmax = z_[0];
|
||||
|
||||
z_d.Create(xnum_, ynum_);
|
||||
for (size_t i = 0; i < ynum_; i++)
|
||||
{
|
||||
for (size_t j = 0; j < xnum_; j++)
|
||||
{
|
||||
z_d.a[j + i*xnum_] = z_[j + i*xnum_];
|
||||
zmin = std::min(zmin, z_[j + i*xnum_]);
|
||||
zmax = std::max(zmax, z_[j + i*xnum_]);
|
||||
}
|
||||
}
|
||||
|
||||
gr->SetSize(600, 600);
|
||||
gr->SetRanges(xmin_, xmax_, ymin_, ymax_, zmin, zmax);
|
||||
//gr->Title(z_ll_.c_str());
|
||||
gr->Colorbar("UbcyqR", 1.0, 0.1, 0.5, 0.8);
|
||||
//gr->Puts(mglPoint(xmax_ + 2, ymax_ + 1), z_ll_.c_str());
|
||||
gr->Box();
|
||||
gr->Axis("x");
|
||||
gr->Axis("y");
|
||||
//gr->Grid("xy", "h:");
|
||||
gr->Label('x', x_ll_.c_str(), 0.0);
|
||||
gr->Label('y', y_ll_.c_str(), 0.0);
|
||||
gr->Dens(z_d);
|
||||
|
||||
//if (file != "null")
|
||||
//{
|
||||
// std::string tp = file.substr(file.find_last_of('.') + 1);
|
||||
// if (tp == "eps") gr->WriteEPS(file.c_str());
|
||||
// if (tp == "png") gr->WritePNG(file.c_str());
|
||||
// if (tp == "jpg") gr->WriteJPEG(file.c_str());
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gctl::mathgl_dens::plot()
|
||||
{
|
||||
mglFLTK gr(this, "GCTL Viewer");
|
||||
return gr.Run();
|
||||
}
|
||||
|
||||
#endif // GCTL_GRAPHIC_MATHGL
|
69
lib/graphic/mathgl_dens.h
Normal file
69
lib/graphic/mathgl_dens.h
Normal file
@ -0,0 +1,69 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#ifndef _GCTL_mathgl_dens_H
|
||||
#define _GCTL_mathgl_dens_H
|
||||
|
||||
#include "gctl_graphic_config.h"
|
||||
|
||||
#ifdef GCTL_GRAPHIC_MATHGL
|
||||
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/maths.h"
|
||||
#include "gctl/algorithm.h"
|
||||
|
||||
#include "mgl2/mgl.h"
|
||||
#include "mgl2/fltk.h"
|
||||
|
||||
namespace gctl
|
||||
{
|
||||
class mathgl_dens : public mglDraw
|
||||
{
|
||||
public:
|
||||
mathgl_dens();
|
||||
virtual ~mathgl_dens();
|
||||
|
||||
void range(double xmin, double xmax, double ymin, double ymax);
|
||||
void demension(int xnum, int ynum);
|
||||
void xlabel(std::string xname);
|
||||
void ylabel(std::string yname);
|
||||
void add_dens(const array<double> &in_z, std::string z_label = "null");
|
||||
int plot();
|
||||
|
||||
int Draw(mglGraph *gr);
|
||||
|
||||
protected:
|
||||
int xnum_, ynum_;
|
||||
double xmin_, xmax_, ymin_, ymax_;
|
||||
std::string x_ll_, y_ll_, z_ll_;
|
||||
array<double> z_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // GCTL_SEISMIC_MATHGL
|
||||
|
||||
#endif // _GCTL_mathgl_dens_H
|
99
lib/graphic/mathgl_plot.cpp
Normal file
99
lib/graphic/mathgl_plot.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#include "mathgl_plot.h"
|
||||
|
||||
#ifdef GCTL_GRAPHIC_MATHGL
|
||||
|
||||
gctl::mathgl_plot::mathgl_plot()
|
||||
{
|
||||
xnum_ = ynum_ = 0;
|
||||
}
|
||||
|
||||
gctl::mathgl_plot::~mathgl_plot(){}
|
||||
|
||||
void gctl::mathgl_plot::init_axis(const array<double> &in_x, std::string x_label)
|
||||
{
|
||||
x_ = in_x;
|
||||
xnum_ = x_.size();
|
||||
x_ll_ = x_label;
|
||||
return;
|
||||
}
|
||||
|
||||
void gctl::mathgl_plot::add_profile(const array<double> &in_y, std::string y_label)
|
||||
{
|
||||
if (xnum_ != in_y.size())
|
||||
throw std::runtime_error("[gctl::mathgl_plot] Invalid profile data size.");
|
||||
|
||||
ys_.append_array(in_y);
|
||||
y_ll_ = y_label;
|
||||
ynum_++;
|
||||
return;
|
||||
}
|
||||
|
||||
int gctl::mathgl_plot::Draw(mglGraph *gr)
|
||||
{
|
||||
mglData x_d, y_d;
|
||||
x_d.Set(x_.get(), x_.size());
|
||||
y_d.Set(ys_.get(), ys_.size());
|
||||
|
||||
double mean = gctl::mean(ys_);
|
||||
double mini = ys_.front(), maxi = ys_.front();
|
||||
for (size_t i = 1; i < ys_.size(); i++)
|
||||
{
|
||||
mini = std::min(mini, ys_[i]);
|
||||
maxi = std::max(maxi, ys_[i]);
|
||||
}
|
||||
|
||||
gr->SetSize(800, 400);
|
||||
gr->SetRanges(x_.front(), x_.back(), mini - 0.5*(mean - mini), maxi + 0.5*(maxi - mean));
|
||||
//gr->Title("Untitled");
|
||||
gr->Box();
|
||||
gr->Axis("x");
|
||||
gr->Axis("y");
|
||||
gr->Grid("xy", "h:");
|
||||
gr->Label('x', x_ll_.c_str(), 0.0);
|
||||
gr->Label('y', y_ll_.c_str(), 0.0);
|
||||
gr->Plot(x_d, y_d, "B");
|
||||
|
||||
//if (file != "null")
|
||||
//{
|
||||
// std::string tp = file.substr(file.find_last_of('.') + 1);
|
||||
// if (tp == "eps") gr->WriteEPS(file.c_str());
|
||||
// if (tp == "png") gr->WritePNG(file.c_str());
|
||||
// if (tp == "jpg") gr->WriteJPEG(file.c_str());
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gctl::mathgl_plot::plot()
|
||||
{
|
||||
mglFLTK gr(this, "GCTL Viewer");
|
||||
return gr.Run();
|
||||
}
|
||||
|
||||
#endif // GCTL_GRAPHIC_MATHGL
|
66
lib/graphic/mathgl_plot.h
Normal file
66
lib/graphic/mathgl_plot.h
Normal file
@ -0,0 +1,66 @@
|
||||
/********************************************************
|
||||
* ██████╗ ██████╗████████╗██╗
|
||||
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
||||
* ██║ ███╗██║ ██║ ██║
|
||||
* ██║ ██║██║ ██║ ██║
|
||||
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
||||
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
||||
* Geophysical Computational Tools & Library (GCTL)
|
||||
*
|
||||
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
*
|
||||
* GCTL is distributed under a dual licensing scheme. You can redistribute
|
||||
* it and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either version 2
|
||||
* of the License, or (at your option) any later version. You should have
|
||||
* received a copy of the GNU Lesser General Public License along with this
|
||||
* program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* If the terms and conditions of the LGPL v.2. would prevent you from using
|
||||
* the GCTL, please consider the option to obtain a commercial license for a
|
||||
* fee. These licenses are offered by the GCTL's original author. As a rule,
|
||||
* licenses are provided "as-is", unlimited in time for a one time fee. Please
|
||||
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
|
||||
* to include some description of your company and the realm of its activities.
|
||||
* Also add information on how to contact you by electronic and paper mail.
|
||||
******************************************************/
|
||||
|
||||
#ifndef _GCTL_mathgl_plot_H
|
||||
#define _GCTL_mathgl_plot_H
|
||||
|
||||
#include "gctl_graphic_config.h"
|
||||
|
||||
#ifdef GCTL_GRAPHIC_MATHGL
|
||||
|
||||
#include "gctl/core.h"
|
||||
#include "gctl/maths.h"
|
||||
#include "gctl/algorithm.h"
|
||||
|
||||
#include "mgl2/mgl.h"
|
||||
#include "mgl2/fltk.h"
|
||||
|
||||
namespace gctl
|
||||
{
|
||||
class mathgl_plot : public mglDraw
|
||||
{
|
||||
public:
|
||||
mathgl_plot();
|
||||
virtual ~mathgl_plot();
|
||||
|
||||
void init_axis(const array<double> &in_x, std::string x_label);
|
||||
void add_profile(const array<double> &in_y, std::string y_label);
|
||||
int plot();
|
||||
|
||||
int Draw(mglGraph *gr);
|
||||
|
||||
protected:
|
||||
int xnum_, ynum_;
|
||||
std::string x_ll_, y_ll_;
|
||||
array<double> x_;
|
||||
array<double> ys_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // GCTL_SEISMIC_MATHGL
|
||||
|
||||
#endif // _GCTL_mathgl_plot_H
|
Loading…
Reference in New Issue
Block a user