mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-24 08:10:16 +00:00
Created a lookup table
This commit is contained in:
parent
f962a40ade
commit
882764a13d
40
src/main.cpp
40
src/main.cpp
@ -63,6 +63,26 @@ std::tuple<double, double> local_to_projected(double* geotransform, int x, int y
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr std::tuple<double, double, double, double> marching_squares_lookup(int mcase)
|
||||||
|
{
|
||||||
|
switch (mcase) {
|
||||||
|
case 1: return {0, 0.5, 0.5, 0};
|
||||||
|
case 2: return {1, 0.5, 0.5, 0};
|
||||||
|
case 3: return {0, 0.5, 1, 0};
|
||||||
|
case 4: return {0.5, 1, 1, 0.5};
|
||||||
|
case 5: return {0, 0, 0, 0}; //FIXME
|
||||||
|
case 6: return {0.5, 1, 0.5, 0};
|
||||||
|
case 7: return {0, 0.5, 0.5, 1};
|
||||||
|
case 8: return {0, 0.5, 0.5, 1};
|
||||||
|
case 9: return {0.5, 1, 0.5, 0};
|
||||||
|
case 10: return {0, 0, 0, 0}; //FIXME
|
||||||
|
case 11: return {0.5, 1, 1, 0.5};
|
||||||
|
case 12: return {0, 0.5, 1, 0.5};
|
||||||
|
case 13: return {0.5, 0, 1, 0.5};
|
||||||
|
case 14: return {0, 0.5, 0.5, 0};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -108,22 +128,23 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
|||||||
for (int j = 0; j < cellmaps.size(); j++)
|
for (int j = 0; j < cellmaps.size(); j++)
|
||||||
{
|
{
|
||||||
CellMap* cellmap = &cellmaps[j];
|
CellMap* cellmap = &cellmaps[j];
|
||||||
OGRFeature *feature;
|
|
||||||
OGRLineString *geometry = new OGRLineString();
|
|
||||||
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
|
||||||
feature->SetField( "Name", j );
|
|
||||||
for (int i = 0; i < cellmap->height*cellmap->width; i++)
|
for (int i = 0; i < cellmap->height*cellmap->width; i++)
|
||||||
{
|
{
|
||||||
if (*(cellmap->cells + i) != 0 && *(cellmap->cells + i) != 15)
|
if (*(cellmap->cells + i) != 0 && *(cellmap->cells + i) != 15)
|
||||||
{
|
{
|
||||||
|
OGRFeature *feature;
|
||||||
|
OGRLineString *geometry = new OGRLineString();
|
||||||
|
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
||||||
|
feature->SetField( "Name", j );
|
||||||
int x_raw = i%cellmap->width;
|
int x_raw = i%cellmap->width;
|
||||||
int y_raw = i/cellmap->width;
|
int y_raw = i/cellmap->width;
|
||||||
auto [x, y] = local_to_projected(cellmap->geotransform, x_raw, y_raw);
|
auto [x, y] = local_to_projected(cellmap->geotransform, x_raw, y_raw);
|
||||||
|
auto [x_bl, y_bl, x_tr, y_tr] = marching_squares_lookup(*(cellmap->cells + i) );
|
||||||
//std::cout << x << ", " << y << " ";
|
//std::cout << x << ", " << y << " ";
|
||||||
geometry->setPoint( geometry->getNumPoints(), 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 );
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
|
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
|
||||||
{
|
{
|
||||||
@ -139,6 +160,11 @@ void write_output_file(std::vector<CellMap> cellmaps, const char *filepath)
|
|||||||
OGRFeature::DestroyFeature( feature );
|
OGRFeature::DestroyFeature( feature );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
GDALClose( poDS );
|
GDALClose( poDS );
|
||||||
/*
|
/*
|
||||||
OGRDataSourceH datasource = OGR_Dr_CreateDataSource(OGRGetDriverByName("GeoJSON"), "contour.geojson", new char*);
|
OGRDataSourceH datasource = OGR_Dr_CreateDataSource(OGRGetDriverByName("GeoJSON"), "contour.geojson", new char*);
|
||||||
|
Loading…
Reference in New Issue
Block a user