v2.0.1 add tin examples

This commit is contained in:
2025-05-19 12:40:06 +08:00
parent 3789f373ce
commit b92f48a4f8
14 changed files with 276 additions and 437 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)