diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a39d5a7 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}/**", + "/opt/stow/gctl/include" + ], + "defines": [], + "macFrameworkPath": [], + "compilerPath": "/opt/homebrew/bin/gcc-11", + "cStandard": "gnu17", + "cppStandard": "gnu++17", + "intelliSenseMode": "macos-gcc-arm64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/demo.cpp b/demo.cpp index e85f11c..76677bf 100644 --- a/demo.cpp +++ b/demo.cpp @@ -3,34 +3,61 @@ #include "fstream" #include "iomanip" +#include "gctl/utility.h" + +#define GRID_FILE "grid-file|grid_file" +#define GRID_PARA "grid-para|grid_para" +#define MAXI_ERR "maxi-error|maxi_error" +#define LOG_FILE "log-file|log_file" +#define NEIGH_FILE "neighbor-file|neighbor_file|neigh-file|neigh_file" +#define SINGLE_Z "single-z" + int main(int argc, char const *argv[]) { - // read dem grid - std::vector topo(10201); - - std::ifstream infile("topo.txt"); - for (int i = 0; i < 10201; ++i) + if (argc < 2) { - infile >> topo[i]; + std::cerr << "Usage: ./tin \n"; + return -1; } - infile.close(); + + gctl::getoption gopt(argv[1]); + gopt.show_options(); + // read dem grid + double xmin, xmax, ymin, ymax, dx, dy; + gctl::parse_string_to_value(gopt.get_value(GRID_PARA), '/', xmin, dx, xmax, ymin, dy, ymax); + + int xnum = round((xmax - xmin)/dx) + 1; + int ynum = round((ymax - ymin)/dy) + 1; + std::vector topo(xnum*ynum); + + double tmp_d; + std::ifstream infile(gopt.get_value(GRID_FILE)); + if (gopt.get_value(SINGLE_Z, false) != "NullValue") + { + for (int i = 0; i < xnum*ynum; ++i) + { + infile >> topo[i]; + } + infile.close(); + } + else + { + for (int i = 0; i < xnum*ynum; ++i) + { + infile >> tmp_d >> tmp_d >> topo[i]; + } + infile.close(); + } + + double maxi_err = std::atof(gopt.get_value(MAXI_ERR).c_str()); std::vector err_records; std::vector tin_vert; std::vector tin_ele; - dem2tin(topo, 0, 1000, 0, 1000, 10, 10, tin_vert, tin_ele, 1.0, &err_records); - - // Write a log file - std::ofstream logfile("topo_TIN.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(); + dem2tin(topo, xmin, xmax, ymin, ymax, dx, dy, tin_vert, tin_ele, maxi_err, &err_records); // Write a Gmsh's .msh file - std::ofstream outfile("topo_TIN.msh"); + std::ofstream outfile(gopt.get_value(GRID_FILE)+".msh"); outfile << "$MeshFormat" << std::endl << "2.2 0 8" << std::endl << "$EndMeshFormat "<neigh[j] != nullptr) + outfile << i + 1; + for (int j = 0; j < 3; j++) { - outfile << " " << tin_ele[i]->neigh[j]->id + 1; + if (tin_ele[i]->neigh[j] != nullptr) + { + outfile << " " << tin_ele[i]->neigh[j]->id + 1; + } + else outfile << " -1"; } - else outfile << " -1"; + outfile << std::endl; } - outfile << std::endl; + outfile.close(); + } + + // Write a log file + std::string log_name = gopt.get_value(LOG_FILE, false); + if (log_name != "NullValue") + { + std::ofstream logfile(log_name+".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(); } - outfile.close(); // Destroy memories allocated by the dem2tin function for (int i = 0; i < tin_vert.size(); ++i) diff --git a/topo_TIN.log b/job.log similarity index 100% rename from topo_TIN.log rename to job.log diff --git a/job.txt b/job.txt new file mode 100644 index 0000000..f01fa00 --- /dev/null +++ b/job.txt @@ -0,0 +1,6 @@ +grid-file = topo +grid-para = 0/10/1000/0/10/1000 +maxi-error = 1.0 +log-file = job +neighbor-file = topo +single-z = yes \ No newline at end of file diff --git a/tin b/tin new file mode 100755 index 0000000..bf8272c Binary files /dev/null and b/tin differ diff --git a/topo.txt b/topo similarity index 100% rename from topo.txt rename to topo diff --git a/topo_TIN.msh b/topo.msh similarity index 100% rename from topo_TIN.msh rename to topo.msh diff --git a/topo_TIN.neigh b/topo.neigh similarity index 100% rename from topo_TIN.neigh rename to topo.neigh diff --git a/topo_TIN.png b/topo_TIN.png deleted file mode 100644 index 3e9ff9d..0000000 Binary files a/topo_TIN.png and /dev/null differ