diff --git a/src/HeightMap.cpp b/src/HeightMap.cpp index 7de83d5..88b78ef 100644 --- a/src/HeightMap.cpp +++ b/src/HeightMap.cpp @@ -21,12 +21,14 @@ HeightMap::HeightMap(const char* filepath) // The heigthmap only has one band auto band = file->GetBands()[0]; // write the attrributes - this->x_size = band->GetXSize(); - this->y_size = band->GetYSize(); + this->width = band->GetXSize(); + this->height = band->GetYSize(); + this->min = band->GetMinimum(); + this->max = band-> GetMaximum(); - this->data = (float *) CPLMalloc(sizeof(float)*x_size*y_size); - band->RasterIO( GF_Read, 0, 0, x_size, y_size, - this->data, x_size, y_size, GDT_Float32, + this->data = (float *) CPLMalloc(sizeof(float)*width*height); + band->RasterIO( GF_Read, 0, 0, width, height, + this->data, width, height, GDT_Float32, 0, 0 ); band->FlushCache(); @@ -34,6 +36,6 @@ HeightMap::HeightMap(const char* filepath) float HeightMap::get_pixel(int x, int y) { // all the pixels are in an array of floats from left to right, top to bottom - int offset = ((this->x_size * y) + x); + int offset = ((this->width * y) + x); return *(this->data + offset); -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/HeightMap.hh b/src/HeightMap.hh index 8d79f3c..b10c9d7 100644 --- a/src/HeightMap.hh +++ b/src/HeightMap.hh @@ -5,8 +5,10 @@ class HeightMap { public: float* data; - int x_size; //!< x dimension in pixels - int y_size; //!< y dimension in pixels + int width; //!< width of image in pixels + int height; //!< height of image in pixels + float min; //!< Minimum value in image + float max; //!< Maximum value in image HeightMap(const char* filepath); float get_pixel(int x,int y); diff --git a/src/main.cpp b/src/main.cpp index 73a3b13..4871dbb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,22 @@ #include "HeightMap.hh" #include +#include int main(int argc, const char* argv[]) { const char* filepath = argv[1]; HeightMap map(filepath); - std::cout << "x: " << map.x_size << " y: " << map.y_size << "\n"; - for (int y = 0; y < map.y_size; y++) + + 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++) { - for (int x = 0; x < map.x_size; x++) + for (int x = 0; x < map.width; x++) { std::cout << map.get_pixel(x, y) << " "; } std::cout << "\n"; } - + std::cout << "\nend🤡\n"; } \ No newline at end of file