v2.0.1 add tin examples
This commit is contained in:
parent
3789f373ce
commit
b92f48a4f8
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
.DS_Store
|
||||
build/
|
||||
.vscode/
|
||||
data/
|
||||
data/
|
||||
bin/
|
216
CMakeLists.txt
216
CMakeLists.txt
@ -1,187 +1,75 @@
|
||||
cmake_minimum_required(VERSION 3.15.2)
|
||||
# 设置项目名称与语言
|
||||
project(GCTL_EXAMPLES VERSION 1.0)
|
||||
project(GCTL_TUTORIALS VERSION 2.0.1)
|
||||
|
||||
# 设置编译选项
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
if(WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -O3")
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
# ExprTK库在macOS 15.4中编译会有错误 添加以下命令对应检查项
|
||||
add_compile_options(-Wno-missing-template-arg-list-after-template-kw)
|
||||
endif()
|
||||
|
||||
# 设置可执行文件的输出地址
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
|
||||
find_package(GCTL)
|
||||
find_package(GCTL_MESH)
|
||||
find_package(GCTL_POTENTIAL)
|
||||
find_package(GCTL_SEISMIC)
|
||||
find_package(GCTL_ELECMAG)
|
||||
find_package(GCTL_GRAPHIC)
|
||||
find_package(GCTL_OPTIMIZATION)
|
||||
find_package(PkgConfig)
|
||||
pkg_search_module(EDITLINE QUIET libeditline)
|
||||
|
||||
if(GCT_FOUND)
|
||||
include_directories(${GCTL_INC_DIR})
|
||||
endif()
|
||||
find_package(GCTL QUIET)
|
||||
find_package(GCTL_MESH QUIET)
|
||||
find_package(GCTL_OPTIMIZATION QUIET)
|
||||
find_package(GCTL_POTENTIAL QUIET)
|
||||
include_directories(${GCTL_INC_DIR})
|
||||
include_directories(${GCTL_MESH_INC_DIR})
|
||||
include_directories(${GCTL_OPTIMIZATION_INC_DIR})
|
||||
include_directories(${GCTL_POTENTIAL_INC_DIR})
|
||||
|
||||
if(GCTL_OPENMP)
|
||||
message(STATUS "GCTL is compiled with OpenMP support.")
|
||||
find_package(OpenMP REQUIRED)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
|
||||
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
|
||||
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
|
||||
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
||||
|
||||
if(GCTL_FOUND)
|
||||
message(STATUS "GCTL Version: " ${GCTL_VERSION})
|
||||
endif()
|
||||
|
||||
if(GCTL_MESH_FOUND)
|
||||
include_directories(${GCTL_MESH_INC_DIR})
|
||||
endif()
|
||||
|
||||
if(GCTL_POTENTIAL_FOUND)
|
||||
include_directories(${GCTL_POTENTIAL_INC_DIR})
|
||||
endif()
|
||||
|
||||
if(GCTL_SEISMIC_FOUND)
|
||||
include_directories(${GCTL_SEISMIC_INC_DIR})
|
||||
endif()
|
||||
|
||||
if(GCTL_ELECMAG_FOUND)
|
||||
include_directories(${GCTL_ELECMAG_INC_DIR})
|
||||
endif()
|
||||
|
||||
if(GCTL_GRAPHIC_FOUND)
|
||||
include_directories(${GCTL_GRAPHIC_INC_DIR})
|
||||
message(STATUS "GCTL_MESH Version: " ${GCTL_MESH_VERSION})
|
||||
endif()
|
||||
|
||||
if(GCTL_OPTIMIZATION_FOUND)
|
||||
include_directories(${GCTL_OPTIMIZATION_INC_DIR})
|
||||
message(STATUS "GCTL_OPTIMIZATION Version: " ${GCTL_OPTIMIZATION_VERSION})
|
||||
endif()
|
||||
|
||||
find_package(LibLCG)
|
||||
if(LibLCG_FOUND)
|
||||
include_directories(${LibLCG_INC_DIR})
|
||||
if(GCTL_POTENTIAL_FOUND)
|
||||
message(STATUS "GCTL_POTENTIAL Version: " ${GCTL_POTENTIAL_VERSION})
|
||||
endif()
|
||||
|
||||
macro(add_example name switch)
|
||||
if(${switch})
|
||||
# 添加可执行程序名称
|
||||
add_executable(${name} examples/${name}.cpp)
|
||||
# 设置安装后的动态库调用地址
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
target_link_libraries(${name} PUBLIC OpenMP::OpenMP_CXX)
|
||||
macro(add_toolkit ex_dir name lib1 lib2 lib3 lib4)
|
||||
#aux_source_directory(${name} src/${ex_dir}/${name}.cpp)
|
||||
add_executable(${name} src/${ex_dir}/${name}.cpp)
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH /usr/local/lib)
|
||||
set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(${lib1})
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_LIB})
|
||||
endif()
|
||||
|
||||
if(${lib2})
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_MESH_LIB})
|
||||
endif()
|
||||
|
||||
# 链接动态库
|
||||
if(GCTL_FOUND)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_LIB})
|
||||
endif()
|
||||
if(${lib3})
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_OPTIMIZATION_LIB})
|
||||
endif()
|
||||
|
||||
if(GCTL_MESH_FOUND)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_MESH_LIB})
|
||||
endif()
|
||||
|
||||
if(GCTL_POTENTIAL_FOUND)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_POTENTIAL_LIB})
|
||||
endif()
|
||||
|
||||
if(GCTL_SEISMIC_FOUND)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_SEISMIC_LIB})
|
||||
endif()
|
||||
|
||||
if(GCTL_ELECMAG_FOUND)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_ELECMAG_LIB})
|
||||
endif()
|
||||
|
||||
if(GCTL_GRAPHIC_FOUND)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_GRAPHIC_LIB})
|
||||
endif()
|
||||
|
||||
if(GCTL_OPTIMIZATION_FOUND)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_OPTIMIZATION_LIB})
|
||||
endif()
|
||||
|
||||
if(LibLCG_FOUND)
|
||||
target_link_libraries(${name} PUBLIC ${LibLCG_LIB})
|
||||
endif()
|
||||
endif()
|
||||
if(${lib4})
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_POTENTIAL_LIB})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(array_ex ON)
|
||||
add_example(sparray_ex ON)
|
||||
add_example(sparray2d_ex ON)
|
||||
add_example(spmat_ex ON)
|
||||
add_example(spmat_ex2 ON)
|
||||
add_example(spmat_ex3 ON)
|
||||
add_example(spmat_ex4 ON)
|
||||
add_example(spmat_ex5 ON)
|
||||
add_example(spmat_ex6 ON)
|
||||
add_example(spmat_ex7 ON)
|
||||
add_example(sptr_ex ON)
|
||||
add_example(stream_ex ON)
|
||||
add_example(stream_template_ex ON)
|
||||
add_example(vector_ex ON)
|
||||
add_example(spmat_inversion_ex ON)
|
||||
add_example(find_index_ex ON)
|
||||
add_example(difference_1d_ex ON)
|
||||
add_example(dynamic_stddev_ex ON)
|
||||
add_example(ellipse_filter_ex ON)
|
||||
add_example(gaussian_hill_ex ON)
|
||||
add_example(mat_inverse_ex ON)
|
||||
add_example(svd_ex ON)
|
||||
add_example(track_ellipse_ex ON)
|
||||
add_example(frac_model_ex ON)
|
||||
add_example(difference_2d_ex ON)
|
||||
add_example(geometry2d_ex ON)
|
||||
add_example(point2d_rotate_ex ON)
|
||||
add_example(point_ex ON)
|
||||
add_example(tensor_ex ON)
|
||||
add_example(entity_ex ON)
|
||||
add_example(cut_2d_tri_mesh_ex ON)
|
||||
add_example(cut_3d_tri_mesh_ex ON)
|
||||
add_example(tetra_neighbor_ex ON)
|
||||
add_example(gobser_tri2d_ex ON)
|
||||
add_example(gobser_rect2d_ex ON)
|
||||
add_example(gobser_polygon_ex ON)
|
||||
add_example(gobser_tricone_ex ON)
|
||||
add_example(gobser_block_ex ON)
|
||||
add_example(gobser_tesseroid_ex ON)
|
||||
add_example(gobser_tetra_sph_ex ON)
|
||||
add_example(mobser_tesseroid_ex ON)
|
||||
add_example(rtp_ex ON)
|
||||
add_example(drtp_ex ON)
|
||||
add_example(gobser_sphere_ex ON)
|
||||
add_example(grav_gradient_ex ON)
|
||||
add_example(mobser_block_ex ON)
|
||||
add_example(mobser_tetra_ex ON)
|
||||
add_example(gobser_tri_ex ON)
|
||||
add_example(gobser_tri_sph_ex ON)
|
||||
add_example(gobser_tetra_ex ON)
|
||||
add_example(getoption_ex ON)
|
||||
add_example(heap_sort_ex ON)
|
||||
add_example(flags_parser_ex ON)
|
||||
add_example(progressbar_ex ON)
|
||||
add_example(basic_io_ex ON)
|
||||
add_example(gmsh_io_ex ON)
|
||||
add_example(surfer_io_ex ON)
|
||||
add_example(triangle_io_ex ON)
|
||||
add_example(xyz_io_ex ON)
|
||||
add_example(text_io_ex ON)
|
||||
add_example(read_netcdf_ex ON)
|
||||
add_example(save_netcdf_ex ON)
|
||||
add_example(griding_ex ON)
|
||||
add_example(mesh_sample1_ex ON)
|
||||
add_example(mesh_sample4_ex ON)
|
||||
add_example(mesh_sample6_ex ON)
|
||||
add_example(mesh_sample7_ex ON)
|
||||
add_example(mesh_sample8_ex ON)
|
||||
add_example(mesh_sample9_ex ON)
|
||||
add_example(mesh_sample10_ex ON)
|
||||
add_example(mesh_sample2_ex ON)
|
||||
add_example(mesh_sample3_ex ON)
|
||||
add_example(mesh_sample5_ex ON)
|
||||
add_example(wavelet_ex ON)
|
||||
add_example(traveltime_tri2d_ex ON)
|
||||
add_example(traveltime_tri2d_ex2 ON)
|
||||
add_example(traveltime_tri2d_ex3 ON)
|
||||
add_example(traveltime_tet3d_ex ON)
|
||||
add_example(traveltime_tet3d_ex2 ON)
|
||||
add_example(gmt_plot_grid_ex ON)
|
||||
add_example(parse_string ON)
|
||||
if(GCTL_FOUND AND GCTL_MESH_FOUND)
|
||||
add_toolkit(mesh create_tin_ex1 ON ON OFF OFF)
|
||||
add_toolkit(mesh create_tin_ex2 ON ON OFF OFF)
|
||||
add_toolkit(mesh create_tin_ex3 ON ON OFF OFF)
|
||||
add_toolkit(mesh create_tin_ex4 ON ON OFF OFF)
|
||||
endif()
|
@ -19,7 +19,7 @@ if [[ $# == 0 || ${1} == "help" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
package=gctl_toolkits
|
||||
package=gctl_tutorials
|
||||
address=/opt/stow
|
||||
taress=/usr/local
|
||||
option="-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${address}/${package}"
|
||||
@ -38,9 +38,9 @@ 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} == "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
|
||||
|
@ -1,13 +0,0 @@
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/examples)
|
||||
|
||||
macro(add_example name)
|
||||
add_executable(${name} ${name}.cpp)
|
||||
target_link_libraries(${name} PUBLIC gctl_ai)
|
||||
endmacro()
|
||||
|
||||
add_example(ex1)
|
||||
add_example(ex2)
|
||||
add_example(ex_mnist)
|
||||
add_example(ex_mnist2)
|
||||
add_example(ex_mnist3)
|
@ -1,41 +0,0 @@
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
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)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(spmat_ex OFF)
|
||||
add_example(eemd_ex OFF)
|
||||
add_example(ceemdan_ex OFF)
|
||||
add_example(fft_ex OFF)
|
||||
add_example(fft2d_ex OFF)
|
||||
add_example(fir_filter_ex OFF)
|
||||
add_example(fft_filter_ex OFF)
|
||||
add_example(windowfunc_ex OFF)
|
||||
add_example(legendre_ex OFF)
|
||||
add_example(refellipsoid_ex OFF)
|
||||
add_example(kde_ex OFF)
|
||||
add_example(meshio_ex OFF)
|
||||
add_example(autodiff_ex OFF)
|
||||
add_example(multinary_ex OFF)
|
||||
add_example(dsv_io_ex OFF)
|
||||
add_example(getoption_ex OFF)
|
||||
add_example(process_ex OFF)
|
||||
add_example(array_ex OFF)
|
||||
add_example(gmt_ex OFF)
|
||||
add_example(gnuplot_ex OFF)
|
||||
add_example(cliplot_ex OFF)
|
||||
add_example(stl_io_ex OFF)
|
||||
add_example(ply_io_ex OFF)
|
||||
add_example(sparray_ex OFF)
|
||||
add_example(sparray2d_ex OFF)
|
@ -1,30 +0,0 @@
|
||||
# 设置可执行文件的输出地址
|
||||
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_mesh)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(mesh_ex1 OFF)
|
||||
add_example(mesh_ex2 OFF)
|
||||
add_example(mesh_ex3 OFF)
|
||||
add_example(mesh_ex4 OFF)
|
||||
add_example(mesh_ex5 OFF)
|
||||
add_example(mesh_ex6 OFF)
|
||||
add_example(mesh_ex7 OFF)
|
||||
add_example(mesh_ex8 OFF)
|
||||
add_example(mesh_ex9 OFF)
|
||||
add_example(mesh_ex10 OFF)
|
||||
add_example(meshio_ex OFF)
|
||||
add_example(tri2d_meshio_ex ON)
|
@ -1,110 +0,0 @@
|
||||
// File: create_tin_ex.cpp
|
||||
// Author: Dr. Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
// Date: 2025-05-15
|
||||
|
||||
#include "gctl/io/file_io.h"
|
||||
#include "gctl/io/gmsh_io.h"
|
||||
#include "gctl/io/dsv_io.h"
|
||||
#include "gctl/mesh/tin.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
// read dem grid
|
||||
std::vector<double> topo(10201);
|
||||
std::ifstream infile("data/mesh/topo");
|
||||
for (int i = 0; i < 10201; ++i)
|
||||
{
|
||||
infile >> topo[i];
|
||||
}
|
||||
infile.close();
|
||||
|
||||
std::vector<tin_vertex2dc> box(4);
|
||||
box[0].id = 0; box[0].x = 500; box[0].y = 250;
|
||||
box[1].id = 1; box[1].x = 750; box[1].y = 250;
|
||||
box[2].id = 2; box[2].x = 750; box[2].y = 500;
|
||||
box[3].id = 3; box[3].x = 500; box[3].y = 500;
|
||||
|
||||
std::vector<region> box_region(1);
|
||||
box_region[0].set(box, 5.0);
|
||||
|
||||
std::vector<double> err_records;
|
||||
std::vector<tin_vertex2dc*> tin_vert;
|
||||
std::vector<tin_triangle*> tin_ele;
|
||||
//grd2tin(topo, 0, 1000, 0, 1000, 10, 10, tin_vert, tin_ele, 1.0, nullptr, &err_records, nullptr);
|
||||
grd2tin(topo, 0, 1000, 0, 1000, 10, 10, tin_vert, tin_ele, 1.0, nullptr, &err_records, &box_region);
|
||||
|
||||
int times = err_records.size();
|
||||
_1d_array errs;
|
||||
errs.input(err_records);
|
||||
destroy_vector(err_records);
|
||||
|
||||
dsv_io log_out;
|
||||
log_out.init_table(err_records.size(), 2);
|
||||
log_out.column_names({"Times", "Maxi-Error"});
|
||||
log_out.fill_column(array<int>(err_records.size(), 1, 1), "Times");
|
||||
log_out.fill_column(errs, "Maxi-Error");
|
||||
log_out.save_csv("data/mesh/topo_TIN.log");
|
||||
|
||||
// Write a Gmsh's .msh file
|
||||
std::ofstream outfile("data/mesh/topo_TIN.msh");
|
||||
outfile << "$MeshFormat" << std::endl << "2.2 0 8" << std::endl << "$EndMeshFormat "<<std::endl;
|
||||
outfile << "$Nodes" << std::endl << tin_vert.size() << std::endl;
|
||||
for (int i = 0; i < tin_vert.size(); i++)
|
||||
{
|
||||
outfile << tin_vert[i]->id + 1 << " " << std::setprecision(16)
|
||||
<< tin_vert[i]->x << " " << tin_vert[i]->y << " " << tin_vert[i]->elev << std::endl;
|
||||
}
|
||||
outfile<<"$EndNodes"<<std::endl;
|
||||
outfile << "$Elements" << std::endl << tin_ele.size() <<std::endl;
|
||||
for (int i = 0; i < tin_ele.size(); i++)
|
||||
{
|
||||
outfile << i + 1 << " 2 0";
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
outfile << " " << tin_ele[i]->vert[j]->id + 1;
|
||||
}
|
||||
outfile << std::endl;
|
||||
}
|
||||
outfile << "$EndElements"<< std::endl;
|
||||
outfile<<"$NodeData"<<std::endl;
|
||||
outfile<<1<<std::endl
|
||||
<<"\"Topography (m)\"" <<std::endl
|
||||
<< 1 <<std::endl<< 0.0 <<std::endl
|
||||
<< 3 <<std::endl<< 0<<std::endl
|
||||
<< 1 <<std::endl<< tin_vert.size() <<std::endl;
|
||||
for (int i = 0; i < tin_vert.size(); i++)
|
||||
{
|
||||
outfile << tin_vert[i]->id + 1 << " " << std::setprecision(16) << tin_vert[i]->elev << std::endl;
|
||||
}
|
||||
outfile << "$EndNodeData" << std::endl;
|
||||
outfile.close();
|
||||
|
||||
// write a neighbor file
|
||||
outfile.open("data/mesh/topo_TIN.neigh");
|
||||
outfile << tin_ele.size() << std::endl;
|
||||
for (int i = 0; i < tin_ele.size(); i++)
|
||||
{
|
||||
outfile << i + 1;
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
if (tin_ele[i]->neigh[j] != nullptr)
|
||||
{
|
||||
outfile << " " << tin_ele[i]->neigh[j]->id + 1;
|
||||
}
|
||||
else outfile << " -1";
|
||||
}
|
||||
outfile << std::endl;
|
||||
}
|
||||
outfile.close();
|
||||
|
||||
// Destroy memories allocated by the dem2tin function
|
||||
destroy_vector(tin_vert);
|
||||
destroy_vector(tin_ele);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
59
src/mesh/create_tin_ex1.cpp
Normal file
59
src/mesh/create_tin_ex1.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
// File: create_tin_ex1.cpp
|
||||
// Author: Dr. Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
// Date: 2025-05-15
|
||||
|
||||
#include "gctl/mesh/tin.h"
|
||||
#include "gctl/io/dsv_io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
// read dem grid
|
||||
std::vector<double> topo(10201);
|
||||
std::ifstream infile("data/mesh/topo");
|
||||
for (int i = 0; i < 10201; ++i)
|
||||
{
|
||||
infile >> topo[i];
|
||||
}
|
||||
infile.close();
|
||||
|
||||
std::vector<vertex3dc> box(4);
|
||||
box[0].set(point3dc(500, 250, 0), 0);
|
||||
box[1].set(point3dc(750, 250, 0), 1);
|
||||
box[2].set(point3dc(750, 500, 0), 2);
|
||||
box[3].set(point3dc(500, 500, 0), 3);
|
||||
|
||||
std::vector<region> box_region(1);
|
||||
box_region[0].set(box, 5.0);
|
||||
|
||||
std::vector<double> err_records;
|
||||
std::vector<vertex3dc*> tin_vert;
|
||||
std::vector<tin_triangle*> tin_ele;
|
||||
grd2tin(topo, 0, 1000, 0, 1000, 10, 10, tin_vert, tin_ele, 1.0, nullptr, &err_records, nullptr);
|
||||
//grd2tin(topo, 0, 1000, 0, 1000, 10, 10, tin_vert, tin_ele, 1.0, nullptr, &err_records, &box_region);
|
||||
|
||||
save_tin2gmsh("data/mesh/tin_out", tin_vert, tin_ele);
|
||||
save_tin2triangle("data/mesh/tin_out", tin_vert, tin_ele);
|
||||
|
||||
int times = err_records.size();
|
||||
_1d_array errs;
|
||||
errs.input(err_records);
|
||||
destroy_vector(err_records);
|
||||
|
||||
dsv_io log_out;
|
||||
log_out.init_table(err_records.size(), 2);
|
||||
log_out.column_names({"Times", "Maxi-Error"});
|
||||
log_out.fill_column(array<int>(err_records.size(), 1, 1), "Times");
|
||||
log_out.fill_column(errs, "Maxi-Error");
|
||||
log_out.save_text("data/mesh/tin_out", ".log");
|
||||
|
||||
// Destroy memories allocated by the dem2tin function
|
||||
destroy_vector(tin_vert);
|
||||
destroy_vector(tin_ele);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
46
src/mesh/create_tin_ex2.cpp
Normal file
46
src/mesh/create_tin_ex2.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
// File: create_tin_ex2.cpp
|
||||
// Author: Dr. Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
// Date: 2025-05-15
|
||||
|
||||
#include "gctl/mesh/tin.h"
|
||||
#include "gctl/io/dsv_io.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
// read dem grid
|
||||
std::vector<dem_point> topo(8000);
|
||||
std::ifstream infile("data/mesh/topo_rnd");
|
||||
for (int i = 0; i < 8000; i++)
|
||||
{
|
||||
infile >> topo[i].x >> topo[i].y >> topo[i].elev;
|
||||
}
|
||||
infile.close();
|
||||
|
||||
std::vector<double> err_records;
|
||||
std::vector<vertex3dc*> tin_vert;
|
||||
std::vector<tin_triangle*> tin_ele;
|
||||
rnd2tin(topo, tin_vert, tin_ele, 1.0, nullptr, &err_records);
|
||||
|
||||
save_tin2gmsh("data/mesh/tin_out", tin_vert, tin_ele);
|
||||
save_tin2triangle("data/mesh/tin_out", tin_vert, tin_ele);
|
||||
|
||||
// Write a log file
|
||||
std::ofstream logfile("data/mesh/tin_out.log");
|
||||
logfile << "Insertion Maxi-Error\n";
|
||||
for (int i = 0; i < err_records.size(); ++i)
|
||||
{
|
||||
logfile << i+1 << " " << err_records[i] << std::endl;
|
||||
}
|
||||
logfile.close();
|
||||
|
||||
// Destroy memories allocated by the dem2tin function
|
||||
destroy_vector(tin_vert);
|
||||
destroy_vector(tin_ele);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
56
src/mesh/create_tin_ex3.cpp
Normal file
56
src/mesh/create_tin_ex3.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
// File: create_tin_ex3.cpp
|
||||
// Author: Dr. Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
// Date: 2025-05-15
|
||||
|
||||
#include "gctl/mesh/tin.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
// read dem grid
|
||||
std::vector<double> topo(10201);
|
||||
std::ifstream infile("data/mesh/topo");
|
||||
for (int i = 0; i < 10201; ++i)
|
||||
{
|
||||
infile >> topo[i];
|
||||
}
|
||||
infile.close();
|
||||
|
||||
// Set outline polygon
|
||||
std::vector<vertex3dc> valid_area(8);
|
||||
valid_area[0].set(point3dc(-5, 500, 0), 0);
|
||||
valid_area[1].set(point3dc(58, 365, 0), 1);
|
||||
valid_area[2].set(point3dc(314, 158, 0), 2);
|
||||
valid_area[3].set(point3dc(681, 22, 0), 3);
|
||||
valid_area[4].set(point3dc(942, 105, 0), 4);
|
||||
valid_area[5].set(point3dc(1005, 360, 0), 5);
|
||||
valid_area[6].set(point3dc(1005, 1005, 0), 6);
|
||||
valid_area[7].set(point3dc(-5, 1005, 0), 7);
|
||||
|
||||
std::vector<double> err_records;
|
||||
std::vector<vertex3dc*> tin_vert;
|
||||
std::vector<tin_triangle*> tin_ele;
|
||||
grd2tin(topo, 0, 1000, 0, 1000, 10, 10, tin_vert, tin_ele, 1.0, &valid_area, &err_records);
|
||||
|
||||
save_tin2gmsh("data/mesh/tin_out", tin_vert, tin_ele);
|
||||
save_tin2triangle("data/mesh/tin_out", tin_vert, tin_ele);
|
||||
|
||||
// Write a log file
|
||||
std::ofstream logfile("data/mesh/tin_out.log");
|
||||
logfile << "Insertion Maxi-Error\n";
|
||||
for (int i = 0; i < err_records.size(); ++i)
|
||||
{
|
||||
logfile << i+1 << " " << err_records[i] << std::endl;
|
||||
}
|
||||
logfile.close();
|
||||
|
||||
// Destroy memories allocated by the dem2tin function
|
||||
destroy_vector(tin_vert);
|
||||
destroy_vector(tin_ele);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
57
src/mesh/create_tin_ex4.cpp
Normal file
57
src/mesh/create_tin_ex4.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// File: create_tin_ex4.cpp
|
||||
// Author: Dr. Yi Zhang (yizhang-geo@zju.edu.cn)
|
||||
// Date: 2025-05-15
|
||||
|
||||
#include "gctl/mesh/tin.h"
|
||||
|
||||
using namespace gctl;
|
||||
|
||||
int main(int argc, char const *argv[]) try
|
||||
{
|
||||
// read dem grid
|
||||
std::vector<dem_point> topo(8000);
|
||||
std::ifstream infile("data/mesh/topo_rnd");
|
||||
for (int i = 0; i < 8000; ++i)
|
||||
{
|
||||
infile >> topo[i].x >> topo[i].y >> topo[i].elev;
|
||||
}
|
||||
infile.close();
|
||||
|
||||
// Set outline polygon
|
||||
std::vector<vertex3dc> valid_area(8);
|
||||
valid_area[0].set(point3dc(-5, 500, 0), 0);
|
||||
valid_area[1].set(point3dc(58, 365, 0), 1);
|
||||
valid_area[2].set(point3dc(314, 158, 0), 2);
|
||||
valid_area[3].set(point3dc(681, 22, 0), 3);
|
||||
valid_area[4].set(point3dc(942, 105, 0), 4);
|
||||
valid_area[5].set(point3dc(1005, 360, 0), 5);
|
||||
valid_area[6].set(point3dc(1005, 1005, 0), 6);
|
||||
valid_area[7].set(point3dc(-5, 1005, 0), 7);
|
||||
|
||||
std::vector<double> err_records;
|
||||
std::vector<vertex3dc*> tin_vert;
|
||||
std::vector<tin_triangle*> tin_ele;
|
||||
rnd2tin(topo, tin_vert, tin_ele, 1.0, &valid_area, &err_records);
|
||||
|
||||
save_tin2gmsh("data/mesh/tin_out", tin_vert, tin_ele);
|
||||
save_tin2triangle("data/mesh/tin_out", tin_vert, tin_ele);
|
||||
|
||||
// Write a log file
|
||||
std::ofstream logfile("data/mesh/tin_out.log");
|
||||
logfile << "Insertion Maxi-Error\n";
|
||||
for (int i = 0; i < err_records.size(); ++i)
|
||||
{
|
||||
logfile << i+1 << " " << err_records[i] << std::endl;
|
||||
}
|
||||
logfile.close();
|
||||
|
||||
// Destroy memories allocated by the dem2tin function
|
||||
for (int i = 0; i < tin_vert.size(); ++i)
|
||||
destroy_vector(tin_vert);
|
||||
destroy_vector(tin_ele);
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/examples)
|
||||
|
||||
macro(add_example name switch)
|
||||
if(${switch})
|
||||
add_executable(${name} ${name}.cpp)
|
||||
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_optimization)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(ex1 OFF)
|
||||
add_example(ex2 OFF)
|
||||
add_example(ex3 OFF)
|
||||
add_example(ex4 OFF)
|
||||
add_example(ex5 OFF)
|
||||
add_example(ex6 OFF)
|
||||
add_example(ex7 OFF)
|
||||
add_example(ex8 OFF)
|
||||
add_example(ex9 OFF)
|
||||
add_example(ex10 OFF)
|
||||
add_example(cfg_ex ON)
|
@ -1,31 +0,0 @@
|
||||
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 CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF)
|
||||
set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
target_link_libraries(${name} PUBLIC gctl_potential)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(gobser_tri2d_ex OFF)
|
||||
add_example(gobser_tri2d_sph_ex OFF)
|
||||
add_example(mobser_dipole_ex OFF)
|
||||
add_example(mobser_block_ex OFF)
|
||||
add_example(mobser_block_gradient_ex OFF)
|
||||
add_example(mobser_tri_ex OFF)
|
||||
add_example(mobser_tri_sph_ex OFF)
|
||||
add_example(mobser_tricone_ex OFF)
|
||||
add_example(mobser_tetra_ex OFF)
|
||||
add_example(mobser_tetra_ex2 OFF)
|
||||
add_example(mobser_tetra_sph_ex OFF)
|
||||
add_example(mobser_tesseroid_ex OFF)
|
||||
add_example(read_IGRF_ex OFF)
|
||||
add_example(read_Swarm_ex OFF)
|
||||
add_example(power_spectrum_ex OFF)
|
||||
add_example(forward_mag_shc OFF)
|
||||
add_example(forward_grav_shc ON)
|
@ -1,20 +0,0 @@
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
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)
|
||||
target_link_libraries(${name} PUBLIC ${GCTL_LIB})
|
||||
target_link_libraries(${name} PUBLIC gctl_seismic)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_example(check_utc_time ON)
|
||||
add_example(check_sig ON)
|
||||
add_example(check_sac ON)
|
||||
add_example(check_xc ON)
|
Loading…
Reference in New Issue
Block a user