diff --git a/src/CaseMap.cpp b/src/CaseMap.cpp index ea72701..f06b4fe 100644 --- a/src/CaseMap.cpp +++ b/src/CaseMap.cpp @@ -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); } \ No newline at end of file diff --git a/src/CaseMap.hh b/src/CaseMap.hh index abf7b4d..78715b4 100644 --- a/src/CaseMap.hh +++ b/src/CaseMap.hh @@ -1,5 +1,5 @@ /** - @brief stores the cases produced from image + @brief stores the cases from marching squars for one elevation level */ class CaseMap { diff --git a/src/main.cpp b/src/main.cpp index 61ddc22..f552ddf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,27 +7,23 @@ #include "gdal/gdal_priv.h" #include - - - -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"; } } \ No newline at end of file