tmp update

This commit is contained in:
张壹 2021-10-15 23:09:02 +08:00
parent 10bb022a07
commit 0acc5cfb05
11 changed files with 23274 additions and 23085 deletions

17
config.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
cmd=${1}
package=libtin
stow_dir=/opt/stow
target_dir=/usr/local
if [[ ${cmd} == "configure" && ! -d "build/" ]]; then
mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=${stow_dir}/${package} -DCMAKE_BUILD_TYPE=Release
elif [[ ${cmd} == "configure" ]]; then
cd build && rm -rf * && cmake .. -DCMAKE_INSTALL_PREFIX=${stow_dir}/${package} -DCMAKE_BUILD_TYPE=Release
elif [[ ${cmd} == "build" ]]; then
cd build && make
elif [[ ${cmd} == "install" ]]; then
cd build && sudo make install
sudo stow --dir=${stow_dir} --target=${target_dir} ${package}
fi

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -16,14 +16,14 @@ int main(int argc, char const *argv[])
// Set outline polygon
std::vector<vertex2dc> valid_area(8);
valid_area[0].set(0, 500, 0, 0);
valid_area[0].set(-5, 500, 0, 0);
valid_area[1].set(58, 365, 0, 1);
valid_area[2].set(314, 158, 0, 2);
valid_area[3].set(681, 22, 0, 3);
valid_area[4].set(942, 105, 0, 4);
valid_area[5].set(1000, 360, 0, 5);
valid_area[6].set(1000, 1000, 0, 6);
valid_area[7].set(0, 1000, 0, 7);
valid_area[5].set(1005, 360, 0, 5);
valid_area[6].set(1005, 1005, 0, 6);
valid_area[7].set(-5, 1005, 0, 7);
std::vector<double> err_records;
std::vector<vertex2dc*> tin_vert;

View File

@ -16,14 +16,14 @@ int main(int argc, char const *argv[])
// Set outline polygon
std::vector<vertex2dc> valid_area(8);
valid_area[0].set(0, 500, 0, 0);
valid_area[0].set(-5, 500, 0, 0);
valid_area[1].set(58, 365, 0, 1);
valid_area[2].set(314, 158, 0, 2);
valid_area[3].set(681, 22, 0, 3);
valid_area[4].set(942, 105, 0, 4);
valid_area[5].set(1000, 360, 0, 5);
valid_area[6].set(1000, 1000, 0, 6);
valid_area[7].set(0, 1000, 0, 7);
valid_area[5].set(1005, 360, 0, 5);
valid_area[6].set(1005, 1005, 0, 6);
valid_area[7].set(-5, 1005, 0, 7);
std::vector<double> err_records;
std::vector<vertex2dc*> tin_vert;

View File

@ -431,12 +431,11 @@ triangle *split_triangle(vertex2dc *v, triangle *t, triangle *new_t[4])
}
// End triangle definition
/**
* @brief Test if the input triangle is inside of the given polygon
*
* @param tri_p Pointer of a test triangle
* @param poly_vert Vertexes of a polygon
* @param poly_vert Vertexes of a polygon. The vertexes should be orderly stored
* @return true The test triangle is inside of the polygon
* @return false The test triangle is outside of the polygon
*/
@ -445,7 +444,7 @@ bool triangle_inside_polygon(triangle *tri_p, std::vector<vertex2dc> *poly_vert)
// If any vertexes of the input triangle is outside of the polygon, return false. Otherwise, return true
if (poly_vert->size() < 3)
{
return false;
return true;
}
else
{
@ -475,21 +474,23 @@ bool triangle_inside_polygon(triangle *tri_p, std::vector<vertex2dc> *poly_vert)
else
{
count = 0;
for (int i = 0; i < pnum; ++i)
{
if ((one_p->y >= poly_vert->at(i).y && one_p->y < poly_vert->at((i+1)%pnum).y) ||
(one_p->y <= poly_vert->at(i).y && one_p->y > poly_vert->at((i+1)%pnum).y))
if (((one_p->y >= poly_vert->at(i).y && one_p->y < poly_vert->at((i+1)%pnum).y) ||
(one_p->y <= poly_vert->at(i).y && one_p->y > poly_vert->at((i+1)%pnum).y)) &&
poly_vert->at(i).y != poly_vert->at((i+1)%pnum).y)
{
tmp_x = (poly_vert->at((i+1)%pnum).x - poly_vert->at(i).x)
* (one_p->y - poly_vert->at(i).y)/(poly_vert->at((i+1)%pnum).y - poly_vert->at(i).y)
+ poly_vert->at(i).x;
if (one_p->x <= tmp_x)
if (one_p->x < tmp_x)
count++;
}
}
if (pow(-1, count) > 0) return false;
if (count != 0 && pow(-1, count) > 0) return false;
}
}
@ -498,6 +499,69 @@ bool triangle_inside_polygon(triangle *tri_p, std::vector<vertex2dc> *poly_vert)
}
}
/**
* @brief Test if the input locaiton is inside of the given polygon
*
* @param x Input x coordinate
* @param y Input y coordinate
* @param poly_vert Vertexes of a polygon. The vertexes should be orderly stored
* @return true The test triangle is inside of the polygon
* @return false The test triangle is outside of the polygon
*/
bool location_inside_polygon(double x, double y, std::vector<vertex2dc> *poly_vert)
{
// If any vertexes of the input triangle is outside of the polygon, return false. Otherwise, return true
if (poly_vert->size() < 3)
{
return true;
}
else
{
int pnum = poly_vert->size();
//确定外接矩形
double xmin = poly_vert->at(0).x, ymin = poly_vert->at(0).y;
double xmax = poly_vert->at(0).x, ymax = poly_vert->at(0).y;
for (int j = 0; j < pnum; ++j)
{
xmin = std::min(xmin, poly_vert->at(j).x);
xmax = std::max(xmax, poly_vert->at(j).x);
ymin = std::min(ymin, poly_vert->at(j).y);
ymax = std::max(ymax, poly_vert->at(j).y);
}
int count;
double tmp_x;
// the testing point is outside of the surrounding box, return false
if (x < xmin || x > xmax || y < ymin || y > ymax)
{
return false;
}
else
{
count = 0;
for (int i = 0; i < pnum; ++i)
{
if (((y >= poly_vert->at(i).y && y < poly_vert->at((i+1)%pnum).y) ||
(y <= poly_vert->at(i).y && y > poly_vert->at((i+1)%pnum).y)) &&
poly_vert->at(i).y != poly_vert->at((i+1)%pnum).y)
{
tmp_x = (poly_vert->at((i+1)%pnum).x - poly_vert->at(i).x)
* (y - poly_vert->at(i).y)/(poly_vert->at((i+1)%pnum).y - poly_vert->at(i).y)
+ poly_vert->at(i).x;
if (x < tmp_x) count++;
}
}
if (count != 0 && pow(-1, count) > 0) return false;
}
return true;
}
}
/**
* @brief Generate the TIN from the DEM grid
@ -571,6 +635,8 @@ void dem2tin(const std::vector<double> &dem, double xmin, double xmax, double ym
// Find host triangle for all DEM locations
int tmp_id;
if (outline_poly == nullptr)
{
for (int i = 0; i < ynum; ++i)
{
for (int j = 0; j < xnum; ++j)
@ -592,6 +658,33 @@ void dem2tin(const std::vector<double> &dem, double xmin, double xmax, double ym
}
}
}
}
else
{
for (int i = 0; i < ynum; ++i)
{
for (int j = 0; j < xnum; ++j)
{
tmp_id = j + i*xnum;
if (tmp_id != 0 && tmp_id != (xnum-1) &&
tmp_id != (xnum*ynum-1) && tmp_id != (xnum*(ynum-1)) &&
location_inside_polygon(xmin+dx*j, ymin+dy*i, outline_poly)) // the four corners are already used
{
tmp_dem = new dem_point(xmin + dx*j, ymin + dy*i, dem[j + i*xnum]);
for (int t = 0; t < out_tris.size(); ++t)
{
if (out_tris[t]->bound_location(tmp_dem->x, tmp_dem->y))
{
tmp_dem->host = out_tris[t];
tmp_dem->err = fabs(out_tris[t]->interpolate(tmp_dem->x, tmp_dem->y) - tmp_dem->elev);
out_tris[t]->hosted_dem.push_back(tmp_dem);
break; // already found, no need to search more
}
}
}
}
}
}
// Sort hosted_dem in the desceding order with respect to the error. Get pointer of the dem_point with maximal error
double maxi_err_tmp = -1.0;
@ -890,6 +983,8 @@ void rnd2tin(const std::vector<dem_point> &dem, std::vector<vertex2dc*> &out_ver
std::vector<dem_point*>::iterator d_iter;
// Find host triangle for all DEM locations
if (outline_poly == nullptr)
{
for (int d = 0; d < dem.size(); ++d)
{
tmp_dem = new dem_point(dem[d].x, dem[d].y, dem[d].elev);
@ -904,6 +999,27 @@ void rnd2tin(const std::vector<dem_point> &dem, std::vector<vertex2dc*> &out_ver
}
}
}
}
else
{
for (int d = 0; d < dem.size(); ++d)
{
if (location_inside_polygon(dem[d].x, dem[d].y, outline_poly))
{
tmp_dem = new dem_point(dem[d].x, dem[d].y, dem[d].elev);
for (int t = 0; t < out_tris.size(); ++t)
{
if (out_tris[t]->bound_location(tmp_dem->x, tmp_dem->y))
{
tmp_dem->host = out_tris[t];
tmp_dem->err = fabs(out_tris[t]->interpolate(tmp_dem->x, tmp_dem->y) - tmp_dem->elev);
out_tris[t]->hosted_dem.push_back(tmp_dem);
break; // already found, no need to search more
}
}
}
}
}
// Sort hosted_dem in the desceding order with respect to the error. Get pointer of the dem_point with maximal error
double maxi_err_tmp = -1.0;

View File

@ -184,16 +184,6 @@ struct triangle
};
// End triangle definition
/**
* @brief Test if the input triangle is inside of the given polygon
*
* @param tri_p Pointer of a test triangle
* @param poly_vert Vertexes of a polygon
* @return true The test triangle is inside of the polygon
* @return false The test triangle is outside of the polygon
*/
bool triangle_inside_polygon(triangle *tri_p, std::vector<vertex2dc> *poly_vert);
/**
* @brief Generate the TIN from a dense DEM grid
*