Use uint8_t instead of int in CaseMap

This commit is contained in:
Trygve 2024-04-11 19:30:09 +02:00
parent ccec7eb1a1
commit f157670d78
3 changed files with 9 additions and 6 deletions

View File

@ -1,6 +1,7 @@
#include <cstdint>
#include "CaseMap.hh" #include "CaseMap.hh"
CaseMap::CaseMap(int width, int height, int* cases) CaseMap::CaseMap(int width, int height, uint8_t* cases)
{ {
this->width = width; this->width = width;
this->height = height; this->height = height;

View File

@ -1,13 +1,14 @@
/** /**
@brief stores the cases from marching squars for one elevation level @brief stores the cases from marching squars for one elevation level
*/ */
#include <cstdint>
class CaseMap class CaseMap
{ {
public: public:
int* cases; uint8_t* cases; //!< pointer to the first case in the array. uint8_t is a 8 bit unsigned integer
int width; //!< width of image in cases int width; //!< width of image in cases
int height; //!< height of image in cases int height; //!< height of image in cases
CaseMap(int width, int height, int* cases); CaseMap(int width, int height, uint8_t* cases);
int get_case(int x,int y); int get_case(int x,int y);
}; };

View File

@ -3,17 +3,18 @@
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
#include <vector> #include <vector>
#include <cstdint>
#include <gdal/gdal.h> #include <gdal/gdal.h>
#include "gdal/gdal_priv.h" #include "gdal/gdal_priv.h"
#include <gdal/gdal_frmts.h> #include <gdal/gdal_frmts.h>
CaseMap produce_casemap(HeightMap* heightmap, float z) CaseMap produce_casemap(HeightMap* heightmap, float z)
{ {
int *cases = (int *) CPLMalloc(sizeof(int)*(heightmap->width-1)*(heightmap->height-1)); uint8_t *cases = (uint8_t *) CPLMalloc(sizeof(uint8_t)*(heightmap->width-1)*(heightmap->height-1));
for (int i = 0; i<(heightmap->width-1)*(heightmap->height-1); i++) { for (int i = 0; i<(heightmap->width-1)*(heightmap->height-1); i++) {
int y = i/(heightmap->width-1); int y = i/(heightmap->width-1);
int x = i%(heightmap->width-1); int x = i%(heightmap->width-1);
int result = (heightmap->get_pixel(x,y+1)>z) + uint8_t result = (heightmap->get_pixel(x,y+1)>z) +
(heightmap->get_pixel(x+1,y+1)>z)*2 + (heightmap->get_pixel(x+1,y+1)>z)*2 +
(heightmap->get_pixel(x+1,y)>z)*4 + (heightmap->get_pixel(x+1,y)>z)*4 +
(heightmap->get_pixel(x,y)>z)*8; (heightmap->get_pixel(x,y)>z)*8;
@ -43,6 +44,6 @@ int main(int argc, const char* argv[])
std::cout << x << ","<< y << "=" << casemap.get_case(x, y) << " "; std::cout << x << ","<< y << "=" << casemap.get_case(x, y) << " ";
} }
} }
std::cout << "\n"; //std::cout << "\n";
} }
} }