update src
This commit is contained in:
parent
85f2c3bf1d
commit
2ab2cbeb31
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal file
@ -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
|
||||||
|
}
|
100
demo.cpp
100
demo.cpp
@ -3,34 +3,61 @@
|
|||||||
#include "fstream"
|
#include "fstream"
|
||||||
#include "iomanip"
|
#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[])
|
int main(int argc, char const *argv[])
|
||||||
{
|
{
|
||||||
// read dem grid
|
if (argc < 2)
|
||||||
std::vector<double> topo(10201);
|
|
||||||
|
|
||||||
std::ifstream infile("topo.txt");
|
|
||||||
for (int i = 0; i < 10201; ++i)
|
|
||||||
{
|
{
|
||||||
infile >> topo[i];
|
std::cerr << "Usage: ./tin <config-file>\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<double> 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<double> err_records;
|
std::vector<double> err_records;
|
||||||
std::vector<vertex2dc*> tin_vert;
|
std::vector<vertex2dc*> tin_vert;
|
||||||
std::vector<triangle*> tin_ele;
|
std::vector<triangle*> tin_ele;
|
||||||
dem2tin(topo, 0, 1000, 0, 1000, 10, 10, tin_vert, tin_ele, 1.0, &err_records);
|
dem2tin(topo, xmin, xmax, ymin, ymax, dx, dy, tin_vert, tin_ele, maxi_err, &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();
|
|
||||||
|
|
||||||
// Write a Gmsh's .msh file
|
// 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 "<<std::endl;
|
outfile << "$MeshFormat" << std::endl << "2.2 0 8" << std::endl << "$EndMeshFormat "<<std::endl;
|
||||||
outfile << "$Nodes" << std::endl << tin_vert.size() << std::endl;
|
outfile << "$Nodes" << std::endl << tin_vert.size() << std::endl;
|
||||||
for (int i = 0; i < tin_vert.size(); i++)
|
for (int i = 0; i < tin_vert.size(); i++)
|
||||||
@ -64,22 +91,39 @@ int main(int argc, char const *argv[])
|
|||||||
outfile.close();
|
outfile.close();
|
||||||
|
|
||||||
// write a neighbor file
|
// write a neighbor file
|
||||||
outfile.open("topo_TIN.neigh");
|
std::string neigh_name = gopt.get_value(NEIGH_FILE, false);
|
||||||
outfile << tin_ele.size() << std::endl;
|
if (neigh_name != "NullValue")
|
||||||
for (int i = 0; i < tin_ele.size(); i++)
|
|
||||||
{
|
{
|
||||||
outfile << i + 1;
|
outfile.open(neigh_name+".neigh");
|
||||||
for (int j = 0; j < 3; j++)
|
outfile << tin_ele.size() << std::endl;
|
||||||
|
for (int i = 0; i < tin_ele.size(); i++)
|
||||||
{
|
{
|
||||||
if (tin_ele[i]->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
|
// Destroy memories allocated by the dem2tin function
|
||||||
for (int i = 0; i < tin_vert.size(); ++i)
|
for (int i = 0; i < tin_vert.size(); ++i)
|
||||||
|
6
job.txt
Normal file
6
job.txt
Normal file
@ -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
|
BIN
topo_TIN.png
BIN
topo_TIN.png
Binary file not shown.
Before Width: | Height: | Size: 612 KiB |
Loading…
Reference in New Issue
Block a user