mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-12-22 05:40:18 +00:00
Use linked list to store the order of the points
This commit is contained in:
parent
4cd4f773bf
commit
4f709d3b07
44
src/main.cpp
44
src/main.cpp
@ -7,12 +7,14 @@
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <gdal/gdal.h>
|
||||
#include "gdal/gdal_priv.h"
|
||||
#include <gdal/gdal_frmts.h>
|
||||
#include <omp.h>
|
||||
#include <fstream>
|
||||
|
||||
std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
|
||||
{
|
||||
@ -45,10 +47,10 @@ 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);
|
||||
@ -86,15 +88,17 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
|
||||
if (current->next == nullptr)
|
||||
{
|
||||
current->endpoint = true;
|
||||
std::cout << "🤕";
|
||||
std::cout << "🤕";std::cout.flush();
|
||||
}
|
||||
|
||||
}
|
||||
vec_private.push_back(points);
|
||||
//vec_private.push_back(points);
|
||||
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;
|
||||
@ -183,33 +187,44 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
|
||||
feature->SetField( "Name", j );
|
||||
|
||||
|
||||
std::vector<Point> points = all_points[j];
|
||||
Point* current = &points[50];
|
||||
std::vector<Point>* points = &all_points[j];
|
||||
|
||||
|
||||
|
||||
Point* current = &points->at(0);
|
||||
int points_allocated = 0;
|
||||
while (true)
|
||||
{
|
||||
//int x_raw = i%width;
|
||||
//int y_raw = i/height;
|
||||
int x_raw = current->x;
|
||||
int y_raw = current->y;
|
||||
/*
|
||||
if (x_raw > 500 || y_raw > 400)
|
||||
{
|
||||
std::cout << "🤯";std::cout.flush();
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
auto [x, y] = local_to_projected(heightmap->geotransform, x_raw, y_raw);
|
||||
//auto [x_bl, y_bl, x_tr, y_tr] = marching_squares_lookup(*(cellmap->cells + i) );
|
||||
//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->allocated = true;
|
||||
current = current->previous;
|
||||
//current sometimes becomes random pointer?????
|
||||
if (current == nullptr)
|
||||
if (current == nullptr or current->allocated)
|
||||
{
|
||||
for (int k = 0; k<points.size(); k++)
|
||||
for (int k = 0; k<points->size(); k++)
|
||||
{
|
||||
if (points[k].endpoint and !points[k].allocated)
|
||||
if (points->at(k).endpoint and !points->at(k).allocated)
|
||||
{
|
||||
current = &points[k];
|
||||
current = &points->at(k);
|
||||
}
|
||||
}
|
||||
if (current == nullptr){std::cout << "🫠"; break; }
|
||||
if (current == nullptr){std::cout << "🫠";std::cout.flush(); break; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +240,6 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
|
||||
exit( 1 );
|
||||
}
|
||||
OGRFeature::DestroyFeature( feature );
|
||||
break;
|
||||
}
|
||||
|
||||
GDALClose( poDS );
|
||||
|
Loading…
Reference in New Issue
Block a user