diff --git a/README.md b/README.md index b51c13b..283b1f1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ This is our project for the INF205: Resource-efficient programming course - [x] Read .tif file into memory using gdal - [ ] Run the marching squares algorithm and produce a "casemap" - [ ] Use a lookuptable to produce a vector file from the "casemap" - +## Dependencies +- GDAL +- OpenMP ## How to build: ``` mkdir build @@ -13,4 +15,4 @@ cd build cmake -DCMAKE_BUILD_TYPE=Debug .. cmake --build . --parallel ``` -Then you can run `./contour-creator` \ No newline at end of file +Then you can run `./contour-creator PATH/TO/HEIGTHMAP.TIF` \ No newline at end of file diff --git a/documentation/plan.pdf b/documentation/plan.pdf deleted file mode 100644 index d5ea89a..0000000 Binary files a/documentation/plan.pdf and /dev/null differ diff --git a/documentation/plan.md b/documentation/report.md similarity index 61% rename from documentation/plan.md rename to documentation/report.md index 5a03363..3cdc274 100644 --- a/documentation/plan.md +++ b/documentation/report.md @@ -1,14 +1,17 @@ ## Group: Trygve and Esther -# What problem will you be working on in your programming project? -We will be implementing a marching squares algorithm to produce a contour map from a heightmap image file. - +# Functionality +Our program usees the marching squares algorithm to create a vector contour map from a raster heightmap. +The cli interface is `gdal_contour [OPTIONS] ` with these options: +``` +-i Interval between contours +-f Fileformat to output +``` +# data structure and input/output +![](ER_diagram.svg) # Responsibilities: Esther will create the algorithm itself with multitreading. This will essentially be a function that takes a grid of pixels as input and returns a similar grid of cells. Trygve will take care of reading in the tiff file into our own datastructure and creating a vector image from the output of the algorithm. # How do you plan to make it easily verifiable that your objectives are reached? We can compare against the `gdal_contour` cli program which is a implementation widely used in other software. We can compare speed, memory usage and the result itself. -Each step in our program also produces a output which we can be worked on and evaluated independently. - -# ER diagram: -![](ER_diagram.svg) \ No newline at end of file +Each step in our program also produces a output which we can be worked on and evaluated independently. \ No newline at end of file diff --git a/documentation/report.pdf b/documentation/report.pdf new file mode 100644 index 0000000..0d12621 Binary files /dev/null and b/documentation/report.pdf differ diff --git a/src/HeightMap.cpp b/src/HeightMap.cpp index 88b78ef..b82e96e 100644 --- a/src/HeightMap.cpp +++ b/src/HeightMap.cpp @@ -1,25 +1,26 @@ +#include + #include #include "gdal/gdal_priv.h" -#include - -#include +#include #include "HeightMap.hh" HeightMap::HeightMap(const char* filepath) { - // Open the file with some gdal nonsense: + // Open the file with gdal: const GDALAccess eAccess = GA_ReadOnly; GDALDatasetUniquePtr file; - GDALAllRegister(); + GDALRegister_GTiff(); file = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen( filepath, eAccess ))); if( !file ) { - std::cout << "Could not open tiff file!"; // handle error + throw std::runtime_error("Could not open tif file!"); } // The heigthmap only has one band auto band = file->GetBands()[0]; + // write the attrributes this->width = band->GetXSize(); this->height = band->GetYSize(); @@ -27,10 +28,10 @@ HeightMap::HeightMap(const char* filepath) this->max = band-> GetMaximum(); this->data = (float *) CPLMalloc(sizeof(float)*width*height); - band->RasterIO( GF_Read, 0, 0, width, height, + CPLErr error = band->RasterIO( GF_Read, 0, 0, width, height, this->data, width, height, GDT_Float32, 0, 0 ); - + if (error) { throw std::runtime_error("Could not read tif file!"); } band->FlushCache(); } float HeightMap::get_pixel(int x, int y) @@ -38,4 +39,4 @@ 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->width * y) + x); return *(this->data + offset); -} \ No newline at end of file +}