59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
// 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);
|
|
} |