mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-24 00:00:17 +00:00
improved vector_cellmap function
This commit is contained in:
parent
0188b9e29d
commit
77467594bd
@ -43,10 +43,13 @@ class Point
|
||||
int x;
|
||||
int y;
|
||||
int mscase;
|
||||
Point * next;
|
||||
Point * previous;
|
||||
Point(int x, int y, int mscase){
|
||||
this -> x = x;
|
||||
this -> y = y;
|
||||
this -> mscase = mscase;
|
||||
|
||||
this -> next = nullptr;
|
||||
this -> previous = nullptr;
|
||||
};
|
||||
};
|
||||
|
45
src/main.cpp
45
src/main.cpp
@ -5,6 +5,7 @@
|
||||
#include <gdal/ogr_feature.h>
|
||||
#include <gdal/ogr_geometry.h>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
@ -15,9 +16,9 @@
|
||||
|
||||
std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
|
||||
{
|
||||
int length = (heightmap->width-1)*(heightmap->height-1);
|
||||
int length = (heightmap->width-1)*(heightmap->height-1); // Defining length of vector
|
||||
uint8_t *cells = (uint8_t *) CPLMalloc(sizeof(uint8_t)*length);
|
||||
std::vector<Point> points;
|
||||
std::vector<Point> points; // Initiating a vector of points
|
||||
for (int i = 0; i<length; i++) {
|
||||
int y = i/(heightmap->width-1);
|
||||
int x = i%(heightmap->width-1);
|
||||
@ -51,37 +52,27 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
|
||||
for (int i = 1; i <= num_contours; i++)
|
||||
{
|
||||
auto points = produce_cellmap(heightmap, heightmap->min + interval*i);
|
||||
std::vector<Point> line;
|
||||
line.push_back(points.back());
|
||||
points.pop_back();
|
||||
|
||||
while (points.size() != 0){
|
||||
Point current_point = points.back();
|
||||
|
||||
for (int j = 0; j < points.size(); j++){
|
||||
Point next = points[j];
|
||||
if (&next != &points.back()) {
|
||||
if (next.x +1 == current_point.x) {
|
||||
line.push_back(next);
|
||||
points.erase(points.begin()+j);
|
||||
Point current = points[j];
|
||||
//std::cout << points_allocated << " " << points.size() << "\n";
|
||||
for (int k = 0; k < points.size(); k++){
|
||||
Point candidate = points[k];
|
||||
if (candidate.next != nullptr) {
|
||||
if (candidate.x +1 == current.x) {
|
||||
current.next = &candidate;
|
||||
}
|
||||
else if (next.x -1 == current_point.x) {
|
||||
line.push_back(next);
|
||||
points.erase(points.begin()+j);
|
||||
else if (candidate.x -1 == current.x) {
|
||||
current.next = &candidate;
|
||||
}
|
||||
else if (next.y +1 == current_point.y) {
|
||||
line.push_back(next);
|
||||
points.erase(points.begin()+j);
|
||||
else if (candidate.y +1 == current.x) {
|
||||
current.next = &candidate;
|
||||
}
|
||||
else if (next.y -1 == current_point.y) {
|
||||
line.push_back(next);
|
||||
points.erase(points.begin()+j);
|
||||
}
|
||||
else {
|
||||
vec_private.push_back(line);
|
||||
std::vector<Point> line;
|
||||
line.push_back(points.back());
|
||||
points.pop_back();
|
||||
else if (candidate.y -1 == current.x) {
|
||||
current.next = &candidate;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user