Added min and max values to HeightMap

This commit is contained in:
Trygve 2024-04-08 17:34:03 +02:00
parent 45fa49a9a8
commit bd9d6e35d0
3 changed files with 21 additions and 13 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -1,18 +1,22 @@
#include "HeightMap.hh"
#include <iostream>
#include <ostream>
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";
}