Started on validation if a case can come after another

This commit is contained in:
Trygve 2024-05-07 15:26:50 +02:00
parent 43f8b78830
commit 47d0e29868

View File

@ -1,4 +1,6 @@
#include "contour_creator.hh" #include "contour_creator.hh"
#include <algorithm>
#include <array>
#include <gdal/ogr_api.h> #include <gdal/ogr_api.h>
#include "ogrsf_frmts.h" #include "ogrsf_frmts.h"
#include <gdal/ogr_core.h> #include <gdal/ogr_core.h>
@ -33,6 +35,11 @@ std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
return points; return points;
} }
bool is_in(int value, std::array<int, 8> array)
{
return std::binary_search(array.begin(), array.end(), value);
}
std::vector<std::vector<Point>> create_lines(HeightMap* heightmap, int interval) std::vector<std::vector<Point>> create_lines(HeightMap* heightmap, int interval)
{ {
int num_contours = (heightmap->max - heightmap->min)/interval; int num_contours = (heightmap->max - heightmap->min)/interval;
@ -51,39 +58,82 @@ std::vector<std::vector<Point>> create_lines(HeightMap* heightmap, int interval)
int points_allocated = 0; int points_allocated = 0;
x = points[0].x; x = points[0].x;
y = points[0].y; y = points[0].y;
int current_case = points[0].mscase;
points[0].allocated = true; points[0].allocated = true;
line.push_back(points[0]); line.push_back(points[0]);
for (int j = 0; j < points.size(); j++){ for (int j = 0; j < points.size(); j++){
for (int k = 0; k < points.size(); k++){ for (int k = 0; k < points.size(); k++){
Point* candidate = &points[k]; Point* candidate = &points[k];
std::array<int,8> north{4, 5,6,7,8,9,10,11};
std::array<int,8> south{1,2,5,6,9,10,13,14};
std::array<int,8> east{2,3,4,5,10,11,12,13};
std::array<int,8> west{1,3,5,7,8,10,12,14};
std::vector<int> possible_connections;
switch (candidate->mscase) {
case 1:
case 14:
possible_connections.insert(possible_connections.end(), east.begin(), east.end());
possible_connections.insert(possible_connections.end(), north.begin(), north.end());
case 2:
case 13:
possible_connections.insert(possible_connections.end(), west.begin(), west.end());
possible_connections.insert(possible_connections.end(), south.begin(), south.end());
case 3:
case 12:
possible_connections.insert(possible_connections.end(), west.begin(), west.end());
possible_connections.insert(possible_connections.end(), east.begin(), east.end());
case 4:
case 11:
possible_connections.insert(possible_connections.end(), west.begin(), west.end());
possible_connections.insert(possible_connections.end(), north.begin(), north.end());
case 5:
case 10:
possible_connections.insert(possible_connections.end(), north.begin(), south.end());
possible_connections.insert(possible_connections.end(), south.begin(), south.end());
possible_connections.insert(possible_connections.end(), west.begin(), west.end());
possible_connections.insert(possible_connections.end(), east.begin(), east.end());
case 6:
case 9:
possible_connections.insert(possible_connections.end(), north.begin(), south.end());
possible_connections.insert(possible_connections.end(), south.begin(), south.end());
case 7:
case 8:
possible_connections.insert(possible_connections.end(), north.begin(), south.end());
possible_connections.insert(possible_connections.end(), east.begin(), east.end());
}
if (!candidate->allocated) { if (!candidate->allocated) {
if (candidate->x == x +1 && candidate->y == y) { if (candidate->x == x +1 && candidate->y == y && is_in(candidate->mscase, west) && is_in(current_case, east)) {
candidate->allocated = true; candidate->allocated = true;
x = candidate->x; x = candidate->x;
y = candidate->y; y = candidate->y;
current_case = candidate->mscase;
line.push_back(*candidate); line.push_back(*candidate);
points_allocated++; points_allocated++;
break; break;
} }
else if (candidate->x == x -1 && candidate->y == y) { else if (candidate->x == x -1 && candidate->y == y && is_in(candidate->mscase, east ) && is_in(current_case, west)) {
x = candidate->x; x = candidate->x;
y = candidate->y; y = candidate->y;
current_case = candidate->mscase;
candidate->allocated = true; candidate->allocated = true;
line.push_back(*candidate); line.push_back(*candidate);
points_allocated++; points_allocated++;
break; break;
} }
else if (candidate->x == x && candidate->y == y + 1) { else if (candidate->x == x && candidate->y == y + 1 && is_in(candidate->mscase, south) && is_in(current_case, north)) {
x = candidate->x; x = candidate->x;
y = candidate->y; y = candidate->y;
current_case = candidate->mscase;
candidate->allocated = true; candidate->allocated = true;
line.push_back(*candidate); line.push_back(*candidate);
points_allocated++; points_allocated++;
break; break;
} }
else if (candidate->x == x && candidate->y == y - 1) { else if (candidate->x == x && candidate->y == y - 1 && is_in(candidate->mscase, north) && is_in(current_case, south)) {
x = candidate->x; x = candidate->x;
y = candidate->y; y = candidate->y;
current_case = candidate->mscase;
candidate->allocated = true; candidate->allocated = true;
line.push_back(*candidate); line.push_back(*candidate);
points_allocated++; points_allocated++;