mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-21 23:00:18 +00:00
Use uint8_t instead of int in CaseMap
This commit is contained in:
parent
ccec7eb1a1
commit
f157670d78
@ -1,6 +1,7 @@
|
||||
#include <cstdint>
|
||||
#include "CaseMap.hh"
|
||||
|
||||
CaseMap::CaseMap(int width, int height, int* cases)
|
||||
CaseMap::CaseMap(int width, int height, uint8_t* cases)
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
@ -1,13 +1,14 @@
|
||||
/**
|
||||
@brief stores the cases from marching squars for one elevation level
|
||||
*/
|
||||
#include <cstdint>
|
||||
class CaseMap
|
||||
{
|
||||
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 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);
|
||||
};
|
@ -3,17 +3,18 @@
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <gdal/gdal.h>
|
||||
#include "gdal/gdal_priv.h"
|
||||
#include <gdal/gdal_frmts.h>
|
||||
|
||||
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++) {
|
||||
int y = 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)>z)*4 +
|
||||
(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 << "\n";
|
||||
//std::cout << "\n";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user