mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-22 07:10:18 +00:00
Merge branch 'main' of gitlab.com:Trygve/contour-creator
This commit is contained in:
commit
666987ca1e
@ -5,7 +5,9 @@ This is our project for the INF205: Resource-efficient programming course
|
|||||||
- [x] Read .tif file into memory using gdal
|
- [x] Read .tif file into memory using gdal
|
||||||
- [ ] Run the marching squares algorithm and produce a "casemap"
|
- [ ] Run the marching squares algorithm and produce a "casemap"
|
||||||
- [ ] Use a lookuptable to produce a vector file from the "casemap"
|
- [ ] Use a lookuptable to produce a vector file from the "casemap"
|
||||||
|
## Dependencies
|
||||||
|
- GDAL
|
||||||
|
- OpenMP
|
||||||
## How to build:
|
## How to build:
|
||||||
```
|
```
|
||||||
mkdir build
|
mkdir build
|
||||||
@ -13,4 +15,4 @@ cd build
|
|||||||
cmake -DCMAKE_BUILD_TYPE=Debug ..
|
cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||||
cmake --build . --parallel
|
cmake --build . --parallel
|
||||||
```
|
```
|
||||||
Then you can run `./contour-creator`
|
Then you can run `./contour-creator PATH/TO/HEIGTHMAP.TIF`
|
Binary file not shown.
@ -1,7 +1,13 @@
|
|||||||
## Group: Trygve and Esther
|
## Group: Trygve and Esther
|
||||||
# What problem will you be working on in your programming project?
|
# Functionality
|
||||||
We will be implementing a marching squares algorithm to produce a contour map from a heightmap image file.
|
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:
|
# 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.
|
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.
|
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?
|
# 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.
|
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.
|
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
BIN
documentation/report.pdf
Normal file
Binary file not shown.
@ -1,25 +1,26 @@
|
|||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <gdal/gdal.h>
|
#include <gdal/gdal.h>
|
||||||
#include "gdal/gdal_priv.h"
|
#include "gdal/gdal_priv.h"
|
||||||
#include <iostream>
|
#include <gdal/gdal_frmts.h>
|
||||||
|
|
||||||
#include <stdfloat>
|
|
||||||
|
|
||||||
#include "HeightMap.hh"
|
#include "HeightMap.hh"
|
||||||
|
|
||||||
HeightMap::HeightMap(const char* filepath)
|
HeightMap::HeightMap(const char* filepath)
|
||||||
{
|
{
|
||||||
// Open the file with some gdal nonsense:
|
// Open the file with gdal:
|
||||||
const GDALAccess eAccess = GA_ReadOnly;
|
const GDALAccess eAccess = GA_ReadOnly;
|
||||||
GDALDatasetUniquePtr file;
|
GDALDatasetUniquePtr file;
|
||||||
GDALAllRegister();
|
GDALRegister_GTiff();
|
||||||
file = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen( filepath, eAccess )));
|
file = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen( filepath, eAccess )));
|
||||||
if( !file )
|
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
|
// The heigthmap only has one band
|
||||||
auto band = file->GetBands()[0];
|
auto band = file->GetBands()[0];
|
||||||
|
|
||||||
// write the attrributes
|
// write the attrributes
|
||||||
this->width = band->GetXSize();
|
this->width = band->GetXSize();
|
||||||
this->height = band->GetYSize();
|
this->height = band->GetYSize();
|
||||||
@ -27,10 +28,10 @@ HeightMap::HeightMap(const char* filepath)
|
|||||||
this->max = band-> GetMaximum();
|
this->max = band-> GetMaximum();
|
||||||
|
|
||||||
this->data = (float *) CPLMalloc(sizeof(float)*width*height);
|
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,
|
this->data, width, height, GDT_Float32,
|
||||||
0, 0 );
|
0, 0 );
|
||||||
|
if (error) { throw std::runtime_error("Could not read tif file!"); }
|
||||||
band->FlushCache();
|
band->FlushCache();
|
||||||
}
|
}
|
||||||
float HeightMap::get_pixel(int x, int y)
|
float HeightMap::get_pixel(int x, int y)
|
||||||
|
Loading…
Reference in New Issue
Block a user