Compare commits

...

4 Commits

Author SHA1 Message Date
Trygve f157670d78 Use uint8_t instead of int in CaseMap 2024-04-11 19:30:09 +02:00
Trygve ccec7eb1a1 Fixed produce_casemap 2024-04-11 18:56:44 +02:00
esther fe2a369225 Calculated cases for casemap 2024-04-11 16:27:03 +02:00
Trygve 1a10f0df33 Fixed some errors 2024-04-11 15:37:33 +02:00
6 changed files with 58 additions and 52 deletions

View File

@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.0)
find_package(GDAL CONFIG REQUIRED)
add_executable(${PROJECT_NAME}
src/HeightMap.cpp src/main.cpp
src/HeightMap.cpp src/CaseMap.cpp src/main.cpp
)

16
src/CaseMap.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <cstdint>
#include "CaseMap.hh"
CaseMap::CaseMap(int width, int height, uint8_t* cases)
{
this->width = width;
this->height = height;
this->cases = cases;
}
int CaseMap::get_case(int x, int y)
{
// 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);
}

14
src/CaseMap.hh Normal file
View File

@ -0,0 +1,14 @@
/**
@brief stores the cases from marching squars for one elevation level
*/
#include <cstdint>
class CaseMap
{
public:
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, uint8_t* cases);
int get_case(int x,int y);
};

View File

@ -1,22 +0,0 @@
#include <gdal/gdal.h>
#include "gdal/gdal_priv.h"
#include <iostream>
#include <stdfloat>
#include "CaseMap.hh"
#include "HeightMap.hh"
CaseMap::CaseMap(int width, int height, int* cases)
{
this->width = width;
this->height = height;
this->cases = 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
int offset = ((this->width * y) + x);
return *(this->cases + offset);
}

View File

@ -1,13 +0,0 @@
/**
@brief stores the cases produced from image
*/
class CaseMap
{
public:
float* data;
int width; //!< width of image in cases
int height; //!< height of image in cases
CaseMap(int width, int height, int* cases);
float get_case(int x,int y);
};

View File

@ -3,19 +3,29 @@
#include <iostream>
#include <ostream>
#include <vector>
#include <cstdint>
#include <gdal/gdal.h>
#include "gdal/gdal_priv.h"
#include <gdal/gdal_frmts.h>
std::vector<CaseMap> produce_casemap(HeightMap* heightmap)
CaseMap produce_casemap(HeightMap* heightmap, float z)
{
std::vector<CaseMap> output;
int* test = (int *) CPLMalloc(sizeof(int)*heightmap->width*heightmap->height);
CaseMap casemap1(heightmap->width-1, heightmap->height-1, test);
output.push_back(casemap1);
return output
}
//(int a, int b, )
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);
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;
*(cases + i) = result;
}
return CaseMap(heightmap->width-1, heightmap->height-1, cases);
}
int main(int argc, const char* argv[])
{
const char* filepath = argv[1];
@ -23,16 +33,17 @@ 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";
for (int y = 0; y < map.height; y++)
auto casemap = produce_casemap(&map, 40.0);
for (int y = 0; y < casemap.height; y++)
{
for (int x = 0; x < map.width; x++)
for (int x = 0; x < casemap.width; x++)
{
std::cout << map.get_pixel(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";
}
std::cout << "\nend🤡\n";
casemap = produce_casemap(map);
std::cout << casemap.get_case( 2, 2)
}