tmp update

This commit is contained in:
张壹 2021-09-22 08:53:23 +08:00
parent 2a281b99e5
commit 47dd2c41b8
9 changed files with 15470 additions and 28396 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
#include "tin.h"
#include "tin_backup.h"
#include "iostream"
#include "fstream"
#include "iomanip"
@ -6,10 +6,10 @@
int main(int argc, char const *argv[])
{
// read dem grid
std::vector<double> topo(10201);
std::vector<double> topo(1002001);
std::ifstream infile("topo.txt");
for (int i = 0; i < 10201; ++i)
std::ifstream infile("topo2.txt");
for (int i = 0; i < 1002001; ++i)
{
infile >> topo[i];
}
@ -18,10 +18,10 @@ int main(int argc, char const *argv[])
std::vector<double> err_records;
std::vector<vertex2dc*> tin_vert;
std::vector<triangle*> tin_ele;
dem2tin(topo, 0, 1000, 0, 1000, 10, 10, tin_vert, tin_ele, 0.5, &err_records);
dem2tin(topo, 0, 1000, 0, 1000, 1, 1, tin_vert, tin_ele, 5.0, &err_records);
// Write a log file
std::ofstream logfile("topo_TIN.log");
std::ofstream logfile("topo2_TIN.log");
logfile << "# Insertion Maxi-Error\n";
for (int i = 0; i < err_records.size(); ++i)
{
@ -30,7 +30,7 @@ int main(int argc, char const *argv[])
logfile.close();
// Write a Gmsh's .msh file
std::ofstream outfile("topo_TIN.msh");
std::ofstream outfile("topo2_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++)
@ -63,6 +63,24 @@ int main(int argc, char const *argv[])
outfile << "$EndNodeData" << std::endl;
outfile.close();
// write a neighbor file
outfile.open("topo2_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
for (int i = 0; i < tin_vert.size(); ++i)
{

View File

@ -286,7 +286,7 @@ void make_delaunay(triangle *t)
dist = (t->cx - n_vert->x) * (t->cx - n_vert->x) +
(t->cy - n_vert->y) * (t->cy - n_vert->y);
if ((dist - t->cr) < 0.0) // need to be flipped
if ((dist - t->cr) < -1.0*ZERO) // need to be flipped
{
flip_neighboring_triangles(t, n_tri, n, v);
@ -322,26 +322,17 @@ triangle *split_triangle(vertex2dc *v, triangle *t, triangle *new_t[4])
new_t[0]->set_neighbor(nullptr, new_t[1], t->neigh[(i+2)%3]);
new_t[1]->set_neighbor(new_t[0], nullptr, t->neigh[(i+1)%3]);
if (new_t[0]->neigh[2] != nullptr)
for (int n = 0; n < 2; n++)
{
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
if (new_t[n]->neigh[2] != nullptr)
{
if (new_t[0]->neigh[2]->neigh[k] == t)
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
{
new_t[0]->neigh[2]->neigh[k] = new_t[0];
break;
}
}
}
if (new_t[1]->neigh[2] != nullptr)
{
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
{
if (new_t[1]->neigh[2]->neigh[k] == t)
{
new_t[1]->neigh[2]->neigh[k] = new_t[1];
break;
if (new_t[n]->neigh[2]->neigh[k] == t)
{
new_t[n]->neigh[2]->neigh[k] = new_t[n];
break;
}
}
}
}
@ -362,50 +353,32 @@ triangle *split_triangle(vertex2dc *v, triangle *t, triangle *new_t[4])
new_t[2]->set_neighbor(new_t[3], new_t[0], t->neigh[i]->neigh[(k+2)%3]);
new_t[3]->set_neighbor(new_t[1], new_t[2], t->neigh[i]->neigh[k]);
if (new_t[0]->neigh[2] != nullptr)
for (int n = 0; n < 2; n++)
{
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
if (new_t[n]->neigh[2] != nullptr)
{
if (new_t[0]->neigh[2]->neigh[k] == t)
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
{
new_t[0]->neigh[2]->neigh[k] = new_t[0];
break;
if (new_t[n]->neigh[2]->neigh[k] == t)
{
new_t[n]->neigh[2]->neigh[k] = new_t[n];
break;
}
}
}
}
if (new_t[1]->neigh[2] != nullptr)
for (int n = 2; n < 4; n++)
{
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
if (new_t[n]->neigh[2] != nullptr)
{
if (new_t[1]->neigh[2]->neigh[k] == t)
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
{
new_t[1]->neigh[2]->neigh[k] = new_t[1];
break;
}
}
}
if (new_t[2]->neigh[2] != nullptr)
{
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
{
if (new_t[2]->neigh[2]->neigh[k] == t->neigh[i])
{
new_t[2]->neigh[2]->neigh[k] = new_t[2];
break;
}
}
}
if (new_t[3]->neigh[2] != nullptr)
{
for (int k = 0; k < 3; ++k) // replace neighbor for the oppositing triangle
{
if (new_t[3]->neigh[2]->neigh[k] == t->neigh[i])
{
new_t[3]->neigh[2]->neigh[k] = new_t[3];
break;
if (new_t[n]->neigh[2]->neigh[k] == t->neigh[i])
{
new_t[n]->neigh[2]->neigh[k] = new_t[n];
break;
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1
topo2_TIN.neigh Normal file
View File

@ -0,0 +1 @@
0

File diff suppressed because it is too large Load Diff

25162
topo_TIN.msh

File diff suppressed because it is too large Load Diff

4448
topo_TIN.neigh Normal file

File diff suppressed because it is too large Load Diff