mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2025-04-17 20:27:20 +00:00
Compare commits
No commits in common. "040e011a66ca7d9bb46ab96a1e1a3a554b2654b0" and "01ddd4e914fac6f07a719fd403d590dc01e55309" have entirely different histories.
040e011a66
...
01ddd4e914
@ -1,15 +1,13 @@
|
|||||||
project(
|
project(
|
||||||
contour-creator
|
contour-creator
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
find_package(GDAL CONFIG REQUIRED)
|
find_package(GDAL CONFIG REQUIRED)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/HeightMap.cpp src/CaseMap.cpp src/main.cpp
|
src/HeightMap.cpp src/CaseMap.cpp src/main.cpp
|
||||||
)
|
)
|
||||||
find_package(OpenMP)
|
|
||||||
if(OpenMP_CXX_FOUND)
|
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} GDAL::GDAL)
|
target_link_libraries(${PROJECT_NAME} GDAL::GDAL)
|
@ -40,6 +40,6 @@ float HeightMap::get_pixel(int x, int y)
|
|||||||
{
|
{
|
||||||
// all the pixels are in an array of floats from left to right, top to bottom
|
// all the pixels are in an array of floats from left to right, top to bottom
|
||||||
int offset = ((this->width * y) + x);
|
int offset = ((this->width * y) + x);
|
||||||
//std::cout << " offset: " << offset << " " << x << ","<< y;
|
std::cout << " " << x << ","<< y;
|
||||||
return *(this->data + offset);
|
return *(this->data + offset);
|
||||||
}
|
}
|
||||||
|
36
src/main.cpp
36
src/main.cpp
@ -9,7 +9,6 @@
|
|||||||
#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>
|
|
||||||
|
|
||||||
CaseMap produce_casemap(HeightMap* heightmap, float z)
|
CaseMap produce_casemap(HeightMap* heightmap, float z)
|
||||||
{
|
{
|
||||||
@ -30,29 +29,7 @@ CaseMap produce_casemap(HeightMap* heightmap, float z)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CaseMap> vector_casemap(HeightMap* heightmap, int interval)
|
void write_output_file(CaseMap* casemap, const char *filepath)
|
||||||
{
|
|
||||||
int num_contours = (heightmap->max - heightmap->min)/interval;
|
|
||||||
std::vector<CaseMap> vector_contours;
|
|
||||||
omp_set_num_threads(12);
|
|
||||||
|
|
||||||
#pragma omp parallel
|
|
||||||
{
|
|
||||||
std::vector<CaseMap> vec_private;
|
|
||||||
#pragma omp for
|
|
||||||
for (int i = 1; i <= num_contours; i++)
|
|
||||||
{
|
|
||||||
vec_private.push_back(produce_casemap(heightmap, heightmap->min + interval*i));
|
|
||||||
std::cout << "Execute thread " << omp_get_num_threads() << " ";
|
|
||||||
}
|
|
||||||
#pragma omp critical
|
|
||||||
vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end());
|
|
||||||
|
|
||||||
}
|
|
||||||
return vector_contours;
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_output_file(std::vector<CaseMap> casemaps, const char *filepath)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
const char *pszDriverName = "ESRI Shapefile";
|
const char *pszDriverName = "ESRI Shapefile";
|
||||||
@ -78,7 +55,7 @@ void write_output_file(std::vector<CaseMap> casemaps, const char *filepath)
|
|||||||
|
|
||||||
OGRLayer *poLayer;
|
OGRLayer *poLayer;
|
||||||
|
|
||||||
poLayer = poDS->CreateLayer( "contours", &(casemaps[0]).reference_system, wkbPoint, NULL );
|
poLayer = poDS->CreateLayer( "contours", &casemap->reference_system, wkbPoint, NULL );
|
||||||
if( poLayer == NULL )
|
if( poLayer == NULL )
|
||||||
{
|
{
|
||||||
printf( "Layer creation failed.\n" );
|
printf( "Layer creation failed.\n" );
|
||||||
@ -94,9 +71,7 @@ void write_output_file(std::vector<CaseMap> casemaps, const char *filepath)
|
|||||||
printf( "Creating Name field failed.\n" );
|
printf( "Creating Name field failed.\n" );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
for (int j = 0; j < casemaps.size(); j++)
|
|
||||||
{
|
|
||||||
CaseMap* casemap = &casemaps[j];
|
|
||||||
for (int i = 0; i<casemap->height*casemap->width; i++) {
|
for (int i = 0; i<casemap->height*casemap->width; i++) {
|
||||||
if (*(casemap->cases + i) != 0 && *(casemap->cases + i) != 15)
|
if (*(casemap->cases + i) != 0 && *(casemap->cases + i) != 15)
|
||||||
{
|
{
|
||||||
@ -133,7 +108,6 @@ void write_output_file(std::vector<CaseMap> casemaps, const char *filepath)
|
|||||||
OGRFeature::DestroyFeature( poFeature );
|
OGRFeature::DestroyFeature( poFeature );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GDALClose( poDS );
|
GDALClose( poDS );
|
||||||
/*
|
/*
|
||||||
@ -168,7 +142,5 @@ int main(int argc, const char* argv[])
|
|||||||
//std::cout << "\n";
|
//std::cout << "\n";
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
write_output_file(&casemap, "out.shp");
|
||||||
auto casemaps = vector_casemap(&map, 5);
|
|
||||||
write_output_file(casemaps, "out.shp");
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user