initial upload
This commit is contained in:
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
|
Reference in New Issue
Block a user