ITS WORKING (somewhat)

This commit is contained in:
Trygve 2024-05-06 23:50:11 +02:00
parent c535eec958
commit 95649f005b

View File

@ -47,24 +47,22 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
std::vector<std::vector<Point>> vector_contours;
omp_set_num_threads(12);
//#pragma omp parallel
#pragma omp parallel
{
std::vector<std::vector<Point>> vec_private;
//#pragma omp for
#pragma omp for
for (int i = 1; i <= num_contours; i++)
{
auto points = produce_cellmap(heightmap, heightmap->min + interval*i);
std::vector<Point> line;
int x;
int y;
int points_allocated = 0;
x = points[0].x;
y = points[0].y;
points[0].allocated = true;
line.push_back(points[0]);
for (int j = 0; j < points.size(); j++){
Point* current = &points[j];
current->allocated=true;
line.push_back(points[j]);
x = points[j].x;
y = points[j].y;
//std::cout << points_allocated << " " << points.size() << "\n";
for (int k = 0; k < points.size(); k++){
Point* candidate = &points[k];
if (!candidate->allocated) {
@ -73,6 +71,7 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
x = candidate->x;
y = candidate->y;
line.push_back(*candidate);
points_allocated++;
break;
}
else if (candidate->x == x -1 && candidate->y == y) {
@ -80,28 +79,43 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
y = candidate->y;
candidate->allocated = true;
line.push_back(*candidate);
points_allocated++;
break;
}
else if (candidate->y == y +1&& candidate->x == x) {
else if (candidate->x == x && candidate->y == y + 1) {
x = candidate->x;
y = candidate->y;
candidate->allocated = true;
line.push_back(*candidate);
points_allocated++;
break;
}
else if (candidate->y == y -1&& candidate->x == x) {
else if (candidate->x == x && candidate->y == y - 1) {
x = candidate->x;
y = candidate->y;
candidate->allocated = true;
line.push_back(*candidate);
points_allocated++;
break;
}
}
}
if (x == points[j].x && y == points[j].y)
if (j > points_allocated)
{
vector_contours.push_back(line);
std::vector<Point> line;
vec_private.push_back(line);
line.clear();
//std::cout << points.size() << " ";
for (int k = 0; k < points.size(); k++){
Point* candidate = &points[k];
if (!candidate->allocated)
{
line.push_back(*candidate);
x = candidate->x;
y = candidate->y;
points_allocated++;
break;
}
}
}
}
@ -109,9 +123,9 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
//vector_contours.push_back(points);
//std::cout << vector_contours.size();
}
//#pragma omp critical
#pragma omp critical
//vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end());
vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end());
}
return vector_contours;
@ -172,7 +186,7 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
OGRLayer *poLayer;
poLayer = poDS->CreateLayer( "contours", /*&(cellmaps[0]).reference_system*/ NULL, wkbLineString, NULL );
poLayer = poDS->CreateLayer( "contours", &heightmap->reference_system, wkbLineString, NULL );
if( poLayer == NULL )
{
printf( "Layer creation failed.\n" );
@ -220,7 +234,7 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
//std::cout << x_raw << ", " << y_raw << " ";std::cout.flush();
//geometry->setPoint( geometry->getNumPoints(), x+x_tr*0.25, y+y_tr*0.25 );
//geometry->setPoint( geometry->getNumPoints(), x+x_bl*0.25, y+y_bl*0.25 );
geometry->setPoint(geometry->getNumPoints(),x_raw ,y_raw );
geometry->setPoint(geometry->getNumPoints(),x ,y );
//current sometimes becomes random pointer?????