mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-12-04 21:10:17 +00:00
Compare commits
4 Commits
25354cc115
...
f157670d78
Author | SHA1 | Date | |
---|---|---|---|
f157670d78 | |||
ccec7eb1a1 | |||
|
fe2a369225 | ||
1a10f0df33 |
@ -6,7 +6,7 @@ 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/main.cpp
|
src/HeightMap.cpp src/CaseMap.cpp src/main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
16
src/CaseMap.cpp
Normal file
16
src/CaseMap.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include "CaseMap.hh"
|
||||||
|
|
||||||
|
CaseMap::CaseMap(int width, int height, uint8_t* cases)
|
||||||
|
{
|
||||||
|
this->width = width;
|
||||||
|
this->height = height;
|
||||||
|
this->cases = cases;
|
||||||
|
|
||||||
|
}
|
||||||
|
int CaseMap::get_case(int x, int y)
|
||||||
|
{
|
||||||
|
// all the cases are in an array of ints from left to right, top to bottom
|
||||||
|
int offset = ((this->width * y) + x);
|
||||||
|
return *(this->cases + offset);
|
||||||
|
}
|
14
src/CaseMap.hh
Normal file
14
src/CaseMap.hh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
@brief stores the cases from marching squars for one elevation level
|
||||||
|
*/
|
||||||
|
#include <cstdint>
|
||||||
|
class CaseMap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uint8_t* cases; //!< pointer to the first case in the array. uint8_t is a 8 bit unsigned integer
|
||||||
|
int width; //!< width of image in cases
|
||||||
|
int height; //!< height of image in cases
|
||||||
|
|
||||||
|
CaseMap(int width, int height, uint8_t* cases);
|
||||||
|
int get_case(int x,int y);
|
||||||
|
};
|
@ -1,22 +0,0 @@
|
|||||||
#include <gdal/gdal.h>
|
|
||||||
#include "gdal/gdal_priv.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <stdfloat>
|
|
||||||
|
|
||||||
#include "CaseMap.hh"
|
|
||||||
#include "HeightMap.hh"
|
|
||||||
|
|
||||||
CaseMap::CaseMap(int width, int height, int* cases)
|
|
||||||
{
|
|
||||||
this->width = width;
|
|
||||||
this->height = height;
|
|
||||||
this->cases = cases;
|
|
||||||
|
|
||||||
}
|
|
||||||
int CaseMap::get_case(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->cases + offset);
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
@brief stores the cases produced from image
|
|
||||||
*/
|
|
||||||
class CaseMap
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
float* data;
|
|
||||||
int width; //!< width of image in cases
|
|
||||||
int height; //!< height of image in cases
|
|
||||||
|
|
||||||
CaseMap(int width, int height, int* cases);
|
|
||||||
float get_case(int x,int y);
|
|
||||||
};
|
|
39
src/main.cpp
39
src/main.cpp
@ -3,18 +3,28 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
#include <gdal/gdal.h>
|
#include <gdal/gdal.h>
|
||||||
|
#include "gdal/gdal_priv.h"
|
||||||
|
#include <gdal/gdal_frmts.h>
|
||||||
|
|
||||||
std::vector<CaseMap> produce_casemap(HeightMap* heightmap)
|
CaseMap produce_casemap(HeightMap* heightmap, float z)
|
||||||
{
|
{
|
||||||
std::vector<CaseMap> output;
|
uint8_t *cases = (uint8_t *) CPLMalloc(sizeof(uint8_t)*(heightmap->width-1)*(heightmap->height-1));
|
||||||
int* test = (int *) CPLMalloc(sizeof(int)*heightmap->width*heightmap->height);
|
for (int i = 0; i<(heightmap->width-1)*(heightmap->height-1); i++) {
|
||||||
CaseMap casemap1(heightmap->width-1, heightmap->height-1, test);
|
int y = i/(heightmap->width-1);
|
||||||
output.push_back(casemap1);
|
int x = i%(heightmap->width-1);
|
||||||
return output
|
uint8_t result = (heightmap->get_pixel(x,y+1)>z) +
|
||||||
|
(heightmap->get_pixel(x+1,y+1)>z)*2 +
|
||||||
|
(heightmap->get_pixel(x+1,y)>z)*4 +
|
||||||
|
(heightmap->get_pixel(x,y)>z)*8;
|
||||||
|
*(cases + i) = result;
|
||||||
}
|
}
|
||||||
//(int a, int b, )
|
|
||||||
|
|
||||||
|
return CaseMap(heightmap->width-1, heightmap->height-1, cases);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
@ -24,15 +34,16 @@ int main(int argc, const char* argv[])
|
|||||||
std::cout << "x: " << map.width << " y: " << map.height << "\n";
|
std::cout << "x: " << map.width << " y: " << map.height << "\n";
|
||||||
std::cout << "max: " << map.max << " min: " << map.min << "\n";
|
std::cout << "max: " << map.max << " min: " << map.min << "\n";
|
||||||
|
|
||||||
for (int y = 0; y < map.height; y++)
|
auto casemap = produce_casemap(&map, 40.0);
|
||||||
|
|
||||||
|
for (int y = 0; y < casemap.height; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < map.width; x++)
|
for (int x = 0; x < casemap.width; x++)
|
||||||
{
|
{
|
||||||
std::cout << map.get_pixel(x, y) << " ";
|
if (casemap.get_case(x, y) && casemap.get_case(x, y)!=15) {
|
||||||
|
std::cout << x << ","<< y << "=" << casemap.get_case(x, y) << " ";
|
||||||
}
|
}
|
||||||
std::cout << "\n";
|
|
||||||
}
|
}
|
||||||
std::cout << "\nend🤡\n";
|
//std::cout << "\n";
|
||||||
casemap = produce_casemap(map);
|
}
|
||||||
std::cout << casemap.get_case( 2, 2)
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user