mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2026-03-15 00:14:04 +00:00
Compare commits
1 Commits
drawing-li
...
restructur
| Author | SHA1 | Date | |
|---|---|---|---|
| e07ab1445a |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "extern/argh"]
|
|
||||||
path = extern/argh
|
|
||||||
url = https://github.com/adishavit/argh.git
|
|
||||||
@@ -1,22 +1,15 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
|
|
||||||
project(
|
project(
|
||||||
contour-creator
|
contour-creator
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
|
||||||
|
find_package(GDAL CONFIG REQUIRED)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/HeightMap.cpp src/CellMap.cpp src/main.cpp
|
src/HeightMap.cpp src/CellMap.cpp src/main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Argh is a simple argrument parser
|
|
||||||
add_subdirectory(extern/argh)
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE argh)
|
|
||||||
|
|
||||||
# Gdal is used for geodata IO
|
|
||||||
find_package(GDAL CONFIG REQUIRED)
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE GDAL::GDAL)
|
|
||||||
|
|
||||||
find_package(OpenMP)
|
find_package(OpenMP)
|
||||||
if(OpenMP_CXX_FOUND)
|
if(OpenMP_CXX_FOUND)
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
|
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} GDAL::GDAL)
|
||||||
@@ -3,4 +3,4 @@ rm -rf build
|
|||||||
mkdir build
|
mkdir build
|
||||||
cmake -DCMAKE_BUILD_TYPE=Debug -B build
|
cmake -DCMAKE_BUILD_TYPE=Debug -B build
|
||||||
cmake --build build --parallel
|
cmake --build build --parallel
|
||||||
build/contour-creator --interval=1 --blur example_files/crop.tif
|
build/contour-creator 'example_files/crop.tif'
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 MiB |
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 88 KiB |
@@ -5,31 +5,16 @@ author:
|
|||||||
- Trygve og Esther
|
- Trygve og Esther
|
||||||
|
|
||||||
---
|
---
|
||||||
|
# What are contours
|
||||||
|
|
||||||
# Output of our program:
|
# Output of our program
|
||||||

|
pretty pictures
|
||||||
|
|
||||||
# Marching squares
|
|
||||||

|
|
||||||
|
|
||||||
# The logical flow of our program
|
# The logical flow of our program
|
||||||
```cpp
|
flowchart
|
||||||
int main(int argc, const char* argv[])
|
|
||||||
{
|
# GDAL
|
||||||
const char* filepath = argv[1];
|
What is it?
|
||||||
HeightMap map(filepath);
|
|
||||||
map.blur(0.8)
|
|
||||||
auto lines = create_lines(&map, 5);
|
|
||||||
write_output_file(cellmaps, "out.geojson", &map);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
# Performance
|
# Performance
|
||||||
| | Time |
|
show the benchmarks
|
||||||
|--------------------|--------------------|
|
|
||||||
| 12 threads | 41s |
|
|
||||||
| 1 thread | 116s |
|
|
||||||
|
|
||||||
|
|
||||||
# Problems we encountered
|
|
||||||
|
|
||||||
1
extern/argh
vendored
1
extern/argh
vendored
Submodule extern/argh deleted from 431bf323ac
@@ -43,10 +43,13 @@ class Point
|
|||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int mscase;
|
int mscase;
|
||||||
bool allocated = false;
|
Point * next;
|
||||||
|
Point * previous;
|
||||||
Point(int x, int y, int mscase){
|
Point(int x, int y, int mscase){
|
||||||
this -> x = x;
|
this -> x = x;
|
||||||
this -> y = y;
|
this -> y = y;
|
||||||
this -> mscase = mscase;
|
this -> mscase = mscase;
|
||||||
|
this -> next = nullptr;
|
||||||
|
this -> previous = nullptr;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
378
src/main.cpp
378
src/main.cpp
@@ -1,22 +1,18 @@
|
|||||||
#include "contour_creator.hh"
|
#include "contour_creator.hh"
|
||||||
#include <algorithm>
|
|
||||||
#include <array>
|
|
||||||
#include <gdal/ogr_api.h>
|
#include <gdal/ogr_api.h>
|
||||||
#include "ogrsf_frmts.h"
|
#include "ogrsf_frmts.h"
|
||||||
#include <gdal/ogr_core.h>
|
#include <gdal/ogr_core.h>
|
||||||
#include <gdal/ogr_feature.h>
|
#include <gdal/ogr_feature.h>
|
||||||
#include <gdal/ogr_geometry.h>
|
#include <gdal/ogr_geometry.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iterator>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <tuple>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <gdal/gdal.h>
|
#include <gdal/gdal.h>
|
||||||
#include "gdal/gdal_priv.h"
|
#include "gdal/gdal_priv.h"
|
||||||
#include <gdal/gdal_frmts.h>
|
#include <gdal/gdal_frmts.h>
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#include "argh.h"
|
|
||||||
|
|
||||||
std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
|
std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
|
||||||
{
|
{
|
||||||
@@ -26,118 +22,20 @@ std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
|
|||||||
for (int i = 0; i<length; i++) {
|
for (int i = 0; i<length; i++) {
|
||||||
int y = i/(heightmap->width-1);
|
int y = i/(heightmap->width-1);
|
||||||
int x = i%(heightmap->width-1);
|
int x = i%(heightmap->width-1);
|
||||||
uint8_t result = (heightmap->get_pixel(x,y)>z)*8 +
|
uint8_t result = (heightmap->get_pixel(x,y)>z) +
|
||||||
(heightmap->get_pixel(x+1,y)>z)*4 +
|
(heightmap->get_pixel(x+1,y)>z)*2 +
|
||||||
(heightmap->get_pixel(x+1,y+1)>z)*2 +
|
(heightmap->get_pixel(x+1,y+1)>z)*4 +
|
||||||
(heightmap->get_pixel(x,y+1)>z);
|
(heightmap->get_pixel(x,y+1)>z)*8;
|
||||||
if (result != 0 and result != 15 ) {
|
if (result != 0 and result != 15 ) {
|
||||||
points.push_back(Point(x, y, result));
|
points.push_back(Point(x, y, result));
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return points;
|
return points;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_in(int value, std::array<int, 8> array)
|
|
||||||
{
|
|
||||||
return std::binary_search(array.begin(), array.end(), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::vector<Point>> create_lines(HeightMap* heightmap, int interval)
|
|
||||||
{
|
|
||||||
int num_contours = (heightmap->max - heightmap->min)/interval;
|
|
||||||
std::vector<std::vector<Point>> vector_contours;
|
|
||||||
|
|
||||||
std::array<int,8> north{4, 5,6,7,8,9,10,11};
|
|
||||||
std::array<int,8> south{1,2,5,6,9,10,13,14};
|
|
||||||
std::array<int,8> east{2,3,4,5,10,11,12,13};
|
|
||||||
std::array<int,8> west{1,3,5,7,8,10,12,14};
|
|
||||||
|
|
||||||
#pragma omp parallel
|
|
||||||
{
|
|
||||||
std::vector<std::vector<Point>> vec_private;
|
|
||||||
#pragma omp for
|
|
||||||
for (int i = 1; i <= num_contours; i++)
|
|
||||||
{
|
|
||||||
auto points = produce_cellmap(heightmap, heightmap->min + interval*i);
|
|
||||||
std::vector<Point> line;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int points_allocated = 0;
|
|
||||||
x = points[0].x;
|
|
||||||
y = points[0].y;
|
|
||||||
int current_case = points[0].mscase;
|
|
||||||
points[0].allocated = true;
|
|
||||||
line.push_back(points[0]);
|
|
||||||
for (int j = 0; j < points.size(); j++){
|
|
||||||
for (int k = 0; k < points.size(); k++){
|
|
||||||
Point* candidate = &points[k];
|
|
||||||
if (!candidate->allocated) {
|
|
||||||
if (candidate->x == x +1 && candidate->y == y /*&& is_in(current_case, east)*/) {
|
|
||||||
candidate->allocated = true;
|
|
||||||
x = candidate->x;
|
|
||||||
y = candidate->y;
|
|
||||||
current_case = candidate->mscase;
|
|
||||||
line.push_back(*candidate);
|
|
||||||
points_allocated++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (candidate->x == x -1 && candidate->y == y /*&& is_in(current_case, west)*/) {
|
|
||||||
x = candidate->x;
|
|
||||||
y = candidate->y;
|
|
||||||
current_case = candidate->mscase;
|
|
||||||
candidate->allocated = true;
|
|
||||||
line.push_back(*candidate);
|
|
||||||
points_allocated++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (candidate->x == x && candidate->y == y + 1 /*&& is_in(current_case, north)*/) {
|
|
||||||
x = candidate->x;
|
|
||||||
y = candidate->y;
|
|
||||||
current_case = candidate->mscase;
|
|
||||||
candidate->allocated = true;
|
|
||||||
line.push_back(*candidate);
|
|
||||||
points_allocated++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (candidate->x == x && candidate->y == y - 1 /*&& is_in(current_case, south)*/) {
|
|
||||||
x = candidate->x;
|
|
||||||
y = candidate->y;
|
|
||||||
current_case = candidate->mscase;
|
|
||||||
candidate->allocated = true;
|
|
||||||
line.push_back(*candidate);
|
|
||||||
points_allocated++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (j > points_allocated)
|
|
||||||
{
|
|
||||||
vec_private.push_back(line);
|
|
||||||
line.clear();
|
|
||||||
//std::cout << points.size() << " ";
|
|
||||||
for (int k = 0; k < points.size(); k++){
|
|
||||||
Point* candidate = &points[k];
|
|
||||||
if (!candidate->allocated)
|
|
||||||
{
|
|
||||||
line.push_back(*candidate);
|
|
||||||
candidate->allocated = true;
|
|
||||||
x = candidate->x;
|
|
||||||
y = candidate->y;
|
|
||||||
current_case = candidate->mscase;
|
|
||||||
points_allocated++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#pragma omp critical
|
|
||||||
|
|
||||||
vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end());
|
|
||||||
}
|
|
||||||
return vector_contours;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::tuple<double, double> local_to_projected(double* geotransform, int x, int y)
|
std::tuple<double, double> local_to_projected(double* geotransform, int x, int y)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
@@ -147,42 +45,139 @@ std::tuple<double, double> local_to_projected(double* geotransform, int x, int y
|
|||||||
geotransform[4] * 0.5 + geotransform[5] * 0.5 + geotransform[3]
|
geotransform[4] * 0.5 + geotransform[5] * 0.5 + geotransform[3]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
std::vector<OGRFeature*> create_contours(OGRFeatureDefn* layer_def, std::vector<Point> points, HeightMap* heightmap)
|
||||||
|
{
|
||||||
|
std::vector<OGRFeature*> lines;
|
||||||
|
for (int i = 0; i<points.size();i++)
|
||||||
|
{
|
||||||
|
OGRFeature *feature;
|
||||||
|
OGRLineString *geometry = new OGRLineString();
|
||||||
|
|
||||||
|
feature = OGRFeature::CreateFeature(layer_def);
|
||||||
|
feature->SetField( "Name", i );
|
||||||
|
Point* current = &points[0];
|
||||||
|
int points_delegated = 0;
|
||||||
|
while (points_delegated < points.size())
|
||||||
|
{
|
||||||
|
//int x_raw = i%width;
|
||||||
|
//int y_raw = i/height;
|
||||||
|
int x_raw = current->x;
|
||||||
|
int y_raw = current->y;
|
||||||
|
auto [x, y] = local_to_projected(heightmap->geotransform, x_raw, y_raw);
|
||||||
|
//std::cout << x << ", " << y << " ";
|
||||||
|
//auto [x_bl, y_bl, x_tr, y_tr] = marching_squares_lookup(*(cellmap->cells + i) );
|
||||||
|
//std::cout << x << ", " << y << " ";
|
||||||
|
//geometry->setPoint( geometry->getNumPoints(), x+x_tr*0.25, y+y_tr*0.25 );
|
||||||
|
//geometry->setPoint( geometry->getNumPoints(), x+x_bl*0.25, y+y_bl*0.25 );
|
||||||
|
geometry->setPoint(geometry->getNumPoints(),x ,y );
|
||||||
|
points_delegated++;
|
||||||
|
current = current->next;
|
||||||
|
if (current == nullptr)
|
||||||
|
{
|
||||||
|
for (int k = 0; k < points.size(); k++)
|
||||||
|
{
|
||||||
|
if (points[k].previous == nullptr)
|
||||||
|
{
|
||||||
|
current = &points[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (current == nullptr)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
|
||||||
|
{
|
||||||
|
printf( "Failed to set geometry.\n" );
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
OGRGeometryFactory::destroyGeometry(geometry);
|
||||||
|
lines.push_back(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<OGRFeature*> vector_cellmap(OGRFeatureDefn* layer_def, HeightMap* heightmap, int interval)
|
||||||
|
{
|
||||||
|
int num_contours = (heightmap->max - heightmap->min)/interval;
|
||||||
|
std::vector<OGRFeature*> vector_contours;
|
||||||
|
omp_set_num_threads(12);
|
||||||
|
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
std::vector<OGRFeature*> lines;
|
||||||
|
#pragma omp for
|
||||||
|
for (int i = 1; i <= num_contours; i++)
|
||||||
|
{
|
||||||
|
auto points = produce_cellmap(heightmap, heightmap->min + interval*i);
|
||||||
|
|
||||||
|
|
||||||
|
for (int j = 0; j < points.size(); j++){
|
||||||
|
Point* current = &points[j];
|
||||||
|
//std::cout << points_allocated << " " << points.size() << "\n";
|
||||||
|
for (int k = 0; k < points.size(); k++){
|
||||||
|
Point* candidate = &points[k];
|
||||||
|
if (candidate->previous == nullptr) {
|
||||||
|
|
||||||
|
if (candidate->x +1 == current->x && candidate->y == current->y) {
|
||||||
|
current->next = candidate;
|
||||||
|
candidate->previous = current;
|
||||||
|
}
|
||||||
|
else if (candidate->x -1 == current->x && candidate->y == current->y) {
|
||||||
|
current->next = candidate;
|
||||||
|
candidate->previous = current;
|
||||||
|
}
|
||||||
|
else if (candidate->y +1 == current->y && candidate->x == current->x) {
|
||||||
|
current->next = candidate;
|
||||||
|
candidate->previous = current;
|
||||||
|
}
|
||||||
|
else if (candidate->y -1 == current->y && candidate->x == current->x) {
|
||||||
|
current->next = candidate;
|
||||||
|
candidate->previous = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto lines = create_lines(layer_def, points, heightmap);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma omp critical
|
||||||
|
|
||||||
|
vector_contours.insert(vector_contours.end(), lines.begin(), lines.end());
|
||||||
|
|
||||||
|
}
|
||||||
|
return vector_contours;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constexpr std::tuple<double, double, double, double> marching_squares_lookup(int mcase)
|
constexpr std::tuple<double, double, double, double> marching_squares_lookup(int mcase)
|
||||||
{
|
{
|
||||||
switch (mcase) {
|
switch (mcase) {
|
||||||
case 1:
|
case 1: return {0, 0.5, 0.5, 0};
|
||||||
return {0, 0.5, 0.5, 0};
|
case 2: return {1, 0.5, 0.5, 0};
|
||||||
case 14:
|
case 3: return {0, 0.5, 1, 0};
|
||||||
return {0.5, 0, 0, 0.5};
|
case 4: return {0.5, 1, 1, 0.5};
|
||||||
case 2:
|
case 5: return {0, 0, 0, 0}; //FIXME
|
||||||
return {0.5, 0, 1, 0.5};
|
case 6: return {0.5, 1, 0.5, 0};
|
||||||
case 13:
|
case 7: return {0, 0.5, 0.5, 1};
|
||||||
return {1, 0.5, 0.5, 0};
|
case 8: return {0, 0.5, 0.5, 1};
|
||||||
case 3:
|
case 9: return {0.5, 1, 0.5, 0};
|
||||||
return {0, 0.5, 1, 0.5};
|
case 10: return {0, 0, 0, 0}; //FIXME
|
||||||
case 12:
|
case 11: return {0.5, 1, 1, 0.5};
|
||||||
return {1, 0.5, 0, 0.5};
|
case 12: return {0, 0.5, 1, 0.5};
|
||||||
case 4:
|
case 13: return {0.5, 0, 1, 0.5};
|
||||||
return {0.5, 1, 1, 0.5};
|
case 14: return {0, 0.5, 0.5, 0};
|
||||||
case 11:
|
|
||||||
return {1, 0.5, 0.5, 1};
|
|
||||||
case 5:
|
|
||||||
case 10:
|
|
||||||
return {0, 0, 0, 0}; //FIXME
|
|
||||||
case 6:
|
|
||||||
return {0.5, 1, 0.5, 0};
|
|
||||||
case 9:
|
|
||||||
return {0.5, 0, 0.5, 1};
|
|
||||||
case 7:
|
|
||||||
return {0, 0.5, 0.5, 1};
|
|
||||||
case 8:
|
|
||||||
return {0.5, 0.5, 0, 0.5};
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void write_output_file(std::vector<std::vector<Point>> all_points, const char *filepath, HeightMap* heightmap)
|
|
||||||
|
|
||||||
|
void write_output_file(const char *filepath, HeightMap* heightmap)
|
||||||
{
|
{
|
||||||
|
|
||||||
const char *pszDriverName = "GeoJSON";
|
const char *pszDriverName = "GeoJSON";
|
||||||
@@ -208,7 +203,7 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
|
|||||||
|
|
||||||
OGRLayer *poLayer;
|
OGRLayer *poLayer;
|
||||||
|
|
||||||
poLayer = poDS->CreateLayer( "contours", &heightmap->reference_system, wkbLineString, NULL );
|
poLayer = poDS->CreateLayer( "contours", /*&(cellmaps[0]).reference_system*/ NULL, wkbLineString, NULL );
|
||||||
if( poLayer == NULL )
|
if( poLayer == NULL )
|
||||||
{
|
{
|
||||||
printf( "Layer creation failed.\n" );
|
printf( "Layer creation failed.\n" );
|
||||||
@@ -228,97 +223,38 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
|
|||||||
int height = heightmap->height -1;
|
int height = heightmap->height -1;
|
||||||
int size = width * height;
|
int size = width * height;
|
||||||
|
|
||||||
for (int j = 0; j < all_points.size(); j++)
|
// gets the lines from the heightmap. Runs the actual algorithm
|
||||||
|
auto lines = create_contours(poLayer->GetLayerDefn(), heightmap, 5);
|
||||||
|
|
||||||
|
|
||||||
|
for (int j = 0; j < lines.size(); j++)
|
||||||
{
|
{
|
||||||
OGRFeature *feature;
|
|
||||||
OGRLineString *geometry = new OGRLineString();
|
|
||||||
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
|
||||||
feature->SetField( "Name", j );
|
|
||||||
|
|
||||||
std::vector<Point> points = all_points[j];
|
if( poLayer->CreateFeature( lines[j] ) != OGRERR_NONE )
|
||||||
|
|
||||||
bool left_to_right = true;
|
|
||||||
|
|
||||||
if ((points[0].y - points[1].y) < 0)
|
|
||||||
left_to_right = true;
|
|
||||||
else
|
|
||||||
left_to_right = false;
|
|
||||||
|
|
||||||
for (int k = 0; k < points.size(); k++)
|
|
||||||
{
|
|
||||||
bool left_to_right = true;
|
|
||||||
|
|
||||||
if ((points[k].x - points[k-1].x) < 0)
|
|
||||||
left_to_right = false;
|
|
||||||
bool top_to_bottom = true;
|
|
||||||
if ((points[k].y - points[k-1].y) < 0)
|
|
||||||
left_to_right = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int x_raw = points[k].x;
|
|
||||||
int y_raw = points[k].y;
|
|
||||||
auto [x, y] = local_to_projected(heightmap->geotransform, x_raw, y_raw);
|
|
||||||
|
|
||||||
auto [x1, y1, x2, y2] = marching_squares_lookup(points[k].mscase);
|
|
||||||
|
|
||||||
if (left_to_right or !top_to_bottom)
|
|
||||||
{
|
{
|
||||||
geometry->setPoint(geometry->getNumPoints(),x + (x1/6) ,y + (y1/6));
|
printf( "Failed to create feature in shapefile.\n" );
|
||||||
geometry->setPoint(geometry->getNumPoints(),x + (x2/6) ,y + (y2/6));
|
exit( 1 );
|
||||||
}
|
}
|
||||||
else {
|
OGRFeature::DestroyFeature( lines[j] );
|
||||||
geometry->setPoint(geometry->getNumPoints(),x + (x2/6) ,y + (y2/6));
|
|
||||||
geometry->setPoint(geometry->getNumPoints(),x + (x1/6) ,y + (y1/6));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
|
|
||||||
{
|
|
||||||
printf( "Failed to set geometry.\n" );
|
|
||||||
exit( 1 );
|
|
||||||
}
|
|
||||||
OGRGeometryFactory::destroyGeometry(geometry);
|
|
||||||
if( poLayer->CreateFeature( feature ) != OGRERR_NONE )
|
|
||||||
{
|
|
||||||
printf( "Failed to create feature in shapefile.\n" );
|
|
||||||
exit( 1 );
|
|
||||||
}
|
|
||||||
OGRFeature::DestroyFeature( feature );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GDALClose( poDS );
|
GDALClose( poDS );
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
argh::parser cmdl(argv);
|
const char* filepath = argv[1];
|
||||||
|
HeightMap map(filepath);
|
||||||
if (cmdl[{ "-h", "--help" }])
|
|
||||||
{
|
|
||||||
std::cout << "Usage:\n"
|
|
||||||
<< "contour_creator [OPTIONS] <input_file>\n"
|
|
||||||
<< "-o; --output <FILENAME.geojson> - File to write output to (Default: contours.geojson)\n"
|
|
||||||
<< "-i; --interval <int> - Set the interval between contours (Default: 5)\n"
|
|
||||||
<< "-b; --blur - Blur the image\n"
|
|
||||||
<< "--stats - Print statistical information about the heightmap\n";
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
int interval;
|
|
||||||
cmdl({"-i", "--interval"}, 5) >> interval;
|
|
||||||
if (interval <= 0)
|
|
||||||
std::cerr << "Interval must be valid positive integer!" << "\n";
|
|
||||||
|
|
||||||
std::string output_file;
|
std::cout << "x: " << map.width << " y: " << map.height << "\n";
|
||||||
cmdl({"-o", "--output"}, "contours.geojson") >> output_file;
|
std::cout << "max: " << map.max << " min: " << map.min << "\n";
|
||||||
|
|
||||||
std::string input_file;
|
map.blur(0.8);
|
||||||
cmdl(1) >> input_file;
|
|
||||||
|
|
||||||
|
auto cellmap = produce_cellmap(&map, 40);
|
||||||
HeightMap map(input_file.c_str());
|
|
||||||
if (cmdl[{"-b", "--blur"}])
|
|
||||||
map.blur(0.8);
|
write_output_file("out.geojson", &map);
|
||||||
auto lines = create_lines(&map, interval);
|
|
||||||
write_output_file(lines, output_file.c_str(), &map);
|
|
||||||
std::cout << "Contours written to " << output_file << " 🗺️\n";
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user