Tried to fix a few things

This commit is contained in:
Robert 2021-04-18 14:33:38 +02:00
parent 8559aca4bb
commit 8864df77d5
4 changed files with 299459 additions and 10 deletions

View file

@ -33,6 +33,7 @@ private:
int r; int r;
int g; int g;
int b; int b;
uint64_t id;
bool visible; bool visible;
enum RenderType { enum RenderType {
FILL, FILL,

299410
res/center.osm Normal file

File diff suppressed because it is too large Load diff

View file

@ -178,10 +178,10 @@ int main(int argc, char** argv)
multipolygon.Draw(renderer); multipolygon.Draw(renderer);
} }
for (Area& area : buildings) //for (Area& area : buildings)
{ //{
filledPolygonRGBA(renderer, area.x, area.y, area.length, area.r, area.g, area.b, 255); // filledPolygonRGBA(renderer, area.x, area.y, area.length, area.r, area.g, area.b, 255);
} //}
for (Highway& highway : highways) for (Highway& highway : highways)
{ {

View file

@ -1,6 +1,8 @@
#include "..\include\multipolygon.hpp" #include "..\include\multipolygon.hpp"
#include <vector> #include <vector>
#include <algorithm>
#include <map>
#include <iostream> #include <iostream>
#include <triangle.h> #include <triangle.h>
@ -23,11 +25,14 @@ inline double Map(double A, double B, double a, double b, double x)
} }
Multipolygon::Multipolygon(const std::shared_ptr<osmp::Relation>& relation, int width, int height, osmp::Bounds bounds) : Multipolygon::Multipolygon(const std::shared_ptr<osmp::Relation>& relation, int width, int height, osmp::Bounds bounds) :
r(255), g(0), b(255), visible(true), rendering(RenderType::FILL) r(255), g(0), b(255), visible(true), rendering(RenderType::FILL), id(relation->id)
{ {
if (relation->HasNullMembers()) if (relation->HasNullMembers())
return; return;
// BREAKIF(7344428);
// BREAKIF(6427823);
std::vector<TriangulationData> data; std::vector<TriangulationData> data;
std::vector<osmp::Relation::Member> ways = relation->GetWays(); std::vector<osmp::Relation::Member> ways = relation->GetWays();
@ -43,7 +48,7 @@ Multipolygon::Multipolygon(const std::shared_ptr<osmp::Relation>& relation, int
std::shared_ptr<osmp::Way> way = std::dynamic_pointer_cast<osmp::Way>(member.member); std::shared_ptr<osmp::Way> way = std::dynamic_pointer_cast<osmp::Way>(member.member);
if (member.role == "inner") if (member.role == "inner")
{ {
if (hasSeenOuter) // TODO: Find better way to sort things if (!hasSeenOuter) // TODO: Find better way to sort things
continue; continue;
if (innerWays.empty() || !lastWasInner) if (innerWays.empty() || !lastWasInner)
@ -140,9 +145,22 @@ Multipolygon::Multipolygon(const std::shared_ptr<osmp::Relation>& relation, int
// Push all vertices to data // Push all vertices to data
std::vector<REAL> vertices; std::vector<REAL> vertices;
std::map<int, int> duplicates;
int n = td.vertices.size() / 2;
for (const std::shared_ptr<osmp::Node>& node : nodes) { for (const std::shared_ptr<osmp::Node>& node : nodes) {
vertices.push_back(Map(bounds.minlon, bounds.maxlon, 0, width, node->lon)); double x = Map(bounds.minlon, bounds.maxlon, 0, width, node->lon);
vertices.push_back(height - Map(bounds.minlat, bounds.maxlat, 0, height, node->lat)); double y = height - Map(bounds.minlat, bounds.maxlat, 0, height, node->lat);
auto xit = std::find(td.vertices.begin(), td.vertices.end(), x);
auto yit = std::find(td.vertices.begin(), td.vertices.end(), y);
if (std::distance(xit, yit) == 1) {
duplicates.insert(std::make_pair(n, std::distance(td.vertices.begin(), xit) / 2));
}
else {
vertices.push_back(x);
vertices.push_back(y);
}
n++;
} }
if (inner) if (inner)
@ -165,8 +183,25 @@ Multipolygon::Multipolygon(const std::shared_ptr<osmp::Relation>& relation, int
// Get segments // Get segments
int segNum = td.vertices.size() / 2; int segNum = td.vertices.size() / 2;
for (int i = 0; i < vertices.size(); i += 2) { for (int i = 0; i < vertices.size(); i += 2) {
td.segments.push_back(segNum); auto dit = duplicates.find(segNum);
td.segments.push_back(++segNum); if (dit != duplicates.end())
{
td.segments.push_back(dit->second);
}
else
{
td.segments.push_back(segNum++);
}
dit = duplicates.find(segNum);
if (dit != duplicates.end())
{
td.segments.push_back(dit->second);
}
else
{
td.segments.push_back(segNum);
}
} }
td.segments.back() = td.vertices.size() / 2; td.segments.back() = td.vertices.size() / 2;
@ -624,6 +659,9 @@ void Multipolygon::Draw(SDL_Renderer* renderer)
if (!visible) if (!visible)
return; return;
// if (id != 6427823)
// return;
for (const Polygon& polygon : polygons) { for (const Polygon& polygon : polygons) {
switch(rendering) switch(rendering)
{ {