Merge branch 'main' of gitlab.com:Trygve/contour-creator

This commit is contained in:
Esther Zijerveld 2024-04-11 15:24:12 +02:00
commit 666987ca1e
5 changed files with 24 additions and 18 deletions

View File

@ -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`
Then you can run `./contour-creator PATH/TO/HEIGTHMAP.TIF`

Binary file not shown.

View File

@ -1,7 +1,13 @@
## 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] <src_filename> <dst_filename>` with these options:
```
-i <elevation intervall> Interval between contours
-f <format> 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.
@ -9,6 +15,3 @@ Trygve will take care of reading in the tiff file into our own datastructure and
# 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)

BIN
documentation/report.pdf Normal file

Binary file not shown.

View File

@ -1,25 +1,26 @@
#include <stdexcept>
#include <gdal/gdal.h>
#include "gdal/gdal_priv.h"
#include <iostream>
#include <stdfloat>
#include <gdal/gdal_frmts.h>
#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)