Fixed produce_casemap

This commit is contained in:
Trygve 2024-04-11 18:56:44 +02:00
parent fe2a369225
commit ccec7eb1a1
3 changed files with 15 additions and 22 deletions

View File

@ -9,7 +9,7 @@ CaseMap::CaseMap(int width, int height, int* cases)
}
int CaseMap::get_case(int x, int y)
{
// all the pixels are in an array of floats from left to right, top to bottom
// all the cases are in an array of ints from left to right, top to bottom
int offset = ((this->width * y) + x);
return *(this->cases + offset);
}

View File

@ -1,5 +1,5 @@
/**
@brief stores the cases produced from image
@brief stores the cases from marching squars for one elevation level
*/
class CaseMap
{

View File

@ -7,27 +7,23 @@
#include "gdal/gdal_priv.h"
#include <gdal/gdal_frmts.h>
CaseMap produce_casemap(HeightMap* heightmap, float height)
CaseMap produce_casemap(HeightMap* heightmap, float z)
{
int* test = (int *) CPLMalloc(sizeof(int)*heightmap->width*heightmap->height);
for (int i; i<(heightmap->width-1)*(heightmap->height-1); i++) {
int *cases = (int *) CPLMalloc(sizeof(int)*(heightmap->width-1)*(heightmap->height-1));
for (int i = 0; i<(heightmap->width-1)*(heightmap->height-1); i++) {
int y = i/(heightmap->width-1);
int x = i%(heightmap->width-1);
*(test + i) = heightmap->get_pixel(x,y+1)*(heightmap->get_pixel(x,y+1)>heightmap->height) +
heightmap->get_pixel(x+1,y+1)*(heightmap->get_pixel(x+1,y+1)>heightmap->height)*2 +
heightmap->get_pixel(x+1,y)*(heightmap->get_pixel(x+1,y)>heightmap->height)*4 +
heightmap->get_pixel(x,y)*(heightmap->get_pixel(x,y)>heightmap->height)*8;
int result = (heightmap->get_pixel(x,y+1)>z) +
(heightmap->get_pixel(x+1,y+1)>z)*2 +
(heightmap->get_pixel(x+1,y)>z)*4 +
(heightmap->get_pixel(x,y)>z)*8;
*(cases + i) = result;
}
return CaseMap(heightmap->width-1, heightmap->height-1, test);
return CaseMap(heightmap->width-1, heightmap->height-1, cases);
}
//(int a, int b, )
int main(int argc, const char* argv[])
{
@ -37,19 +33,16 @@ int main(int argc, const char* argv[])
std::cout << "x: " << map.width << " y: " << map.height << "\n";
std::cout << "max: " << map.max << " min: " << map.min << "\n";
std::cout << "\nend🤡\n";
auto casemap = produce_casemap(&map, 40.0);
for (int y = 0; y < casemap.height; y++)
{
for (int x = 0; x < casemap.width; x++)
{
if (casemap.get_case(x, y)) {
std::cout << casemap.get_case(x, y) << " ";
if (casemap.get_case(x, y) && casemap.get_case(x, y)!=15) {
std::cout << x << ","<< y << "=" << casemap.get_case(x, y) << " ";
}
}
// std::cout << "\n";
std::cout << "\n";
}
}