mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-21 23:00:18 +00:00
Started on continus line drawing
This commit is contained in:
parent
77467594bd
commit
9d8df3256d
@ -45,6 +45,8 @@ class Point
|
|||||||
int mscase;
|
int mscase;
|
||||||
Point * next;
|
Point * next;
|
||||||
Point * previous;
|
Point * previous;
|
||||||
|
bool endpoint = false;
|
||||||
|
bool allocated = false;
|
||||||
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;
|
||||||
|
106
src/main.cpp
106
src/main.cpp
@ -53,29 +53,37 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
|
|||||||
{
|
{
|
||||||
auto points = produce_cellmap(heightmap, heightmap->min + interval*i);
|
auto points = produce_cellmap(heightmap, heightmap->min + interval*i);
|
||||||
|
|
||||||
|
|
||||||
for (int j = 0; j < points.size(); j++){
|
for (int j = 0; j < points.size(); j++){
|
||||||
Point current = points[j];
|
Point* current = &points[j];
|
||||||
//std::cout << points_allocated << " " << points.size() << "\n";
|
//std::cout << points_allocated << " " << points.size() << "\n";
|
||||||
for (int k = 0; k < points.size(); k++){
|
for (int k = 0; k < points.size(); k++){
|
||||||
Point candidate = points[k];
|
Point* candidate = &points[k];
|
||||||
if (candidate.next != nullptr) {
|
if (candidate->previous == nullptr and candidate != current->previous) {
|
||||||
if (candidate.x +1 == current.x) {
|
|
||||||
current.next = &candidate;
|
|
||||||
}
|
|
||||||
else if (candidate.x -1 == current.x) {
|
|
||||||
current.next = &candidate;
|
|
||||||
}
|
|
||||||
else if (candidate.y +1 == current.x) {
|
|
||||||
current.next = &candidate;
|
|
||||||
}
|
|
||||||
else if (candidate.y -1 == current.x) {
|
|
||||||
current.next = &candidate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
current->endpoint = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
vec_private.push_back(points);
|
||||||
}
|
}
|
||||||
#pragma omp critical
|
#pragma omp critical
|
||||||
|
|
||||||
@ -162,47 +170,55 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
|
|||||||
|
|
||||||
for (int j = 0; j < all_points.size(); j++)
|
for (int j = 0; j < all_points.size(); j++)
|
||||||
{
|
{
|
||||||
OGRFeature *feature;
|
OGRFeature *feature;
|
||||||
OGRLineString *geometry = new OGRLineString();
|
OGRLineString *geometry = new OGRLineString();
|
||||||
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
|
||||||
feature->SetField( "Name", j );
|
feature->SetField( "Name", j );
|
||||||
|
|
||||||
|
|
||||||
std::vector<Point> points = all_points[j];
|
std::vector<Point> points = all_points[j];
|
||||||
|
Point* current = &points[0];
|
||||||
for (int i = 0; i < points.size(); i++)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
||||||
//int x_raw = i%width;
|
//int x_raw = i%width;
|
||||||
//int y_raw = i/height;
|
//int y_raw = i/height;
|
||||||
int x_raw = points[i].x;
|
int x_raw = current->x;
|
||||||
int y_raw = points[i].y;
|
int y_raw = current->y;
|
||||||
auto [x, y] = local_to_projected(heightmap->geotransform, x_raw, y_raw);
|
auto [x, y] = local_to_projected(heightmap->geotransform, x_raw, y_raw);
|
||||||
//auto [x_bl, y_bl, x_tr, y_tr] = marching_squares_lookup(*(cellmap->cells + i) );
|
//auto [x_bl, y_bl, x_tr, y_tr] = marching_squares_lookup(*(cellmap->cells + i) );
|
||||||
//std::cout << x << ", " << y << " ";
|
//std::cout << x_raw << ", " << y_raw << " ";std::cout.flush();
|
||||||
//geometry->setPoint( geometry->getNumPoints(), x+x_tr*0.25, y+y_tr*0.25 );
|
//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+x_bl*0.25, y+y_bl*0.25 );
|
||||||
geometry->setPoint(geometry->getNumPoints(),x ,y );
|
geometry->setPoint(geometry->getNumPoints(),x_raw ,y_raw );
|
||||||
|
current->allocated = true;
|
||||||
|
current = current->previous;
|
||||||
|
//current sometimes becomes random pointer?????
|
||||||
|
if (current == nullptr)
|
||||||
|
{
|
||||||
|
for (int k = 0; k<points.size(); k++)
|
||||||
|
{
|
||||||
|
if (points[k].endpoint and !points[k].allocated)
|
||||||
|
{
|
||||||
|
current = &points[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (current == nullptr){std::cout << "🫠"; break; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
|
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
|
||||||
{
|
{
|
||||||
printf( "Failed to set geometry.\n" );
|
printf( "Failed to set geometry.\n" );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
OGRGeometryFactory::destroyGeometry(geometry);
|
OGRGeometryFactory::destroyGeometry(geometry);
|
||||||
if( poLayer->CreateFeature( feature ) != OGRERR_NONE )
|
if( poLayer->CreateFeature( feature ) != OGRERR_NONE )
|
||||||
{
|
{
|
||||||
printf( "Failed to create feature in shapefile.\n" );
|
printf( "Failed to create feature in shapefile.\n" );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
OGRFeature::DestroyFeature( feature );
|
OGRFeature::DestroyFeature( feature );
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GDALClose( poDS );
|
GDALClose( poDS );
|
||||||
|
Loading…
Reference in New Issue
Block a user