Changeset View
Changeset View
Standalone View
Standalone View
tools/vectorosm-tilecreator/NodeReducer.cpp
1 | // | 1 | // | ||
---|---|---|---|---|---|
2 | // This file is part of the Marble Virtual Globe. | 2 | // This file is part of the Marble Virtual Globe. | ||
3 | // | 3 | // | ||
4 | // This program is free software licensed under the GNU LGPL. You can | 4 | // This program is free software licensed under the GNU LGPL. You can | ||
5 | // find a copy of this license in LICENSE.txt in the top directory of | 5 | // find a copy of this license in LICENSE.txt in the top directory of | ||
6 | // the source code. | 6 | // the source code. | ||
7 | // | 7 | // | ||
8 | // Copyright 2016 Akshat Tandon <akshat.tandon@research.iiit.ac.in> | 8 | // Copyright 2016 Akshat Tandon <akshat.tandon@research.iiit.ac.in> | ||
9 | // | 9 | // | ||
10 | 10 | | |||
11 | #include "GeoDataPlacemark.h" | 11 | #include "GeoDataPlacemark.h" | ||
12 | #include "GeoDataLineString.h" | 12 | #include "GeoDataLineString.h" | ||
13 | #include "GeoDataPolygon.h" | 13 | #include "GeoDataPolygon.h" | ||
14 | #include "GeoDataBuilding.h" | ||||
15 | #include "GeoDataMultiGeometry.h" | ||||
14 | #include "GeoDataCoordinates.h" | 16 | #include "GeoDataCoordinates.h" | ||
15 | #include "MarbleMath.h" | 17 | #include "MarbleMath.h" | ||
16 | #include "NodeReducer.h" | 18 | #include "NodeReducer.h" | ||
17 | #include "OsmPlacemarkData.h" | 19 | #include "OsmPlacemarkData.h" | ||
18 | 20 | | |||
19 | #include <QDebug> | 21 | #include <QDebug> | ||
20 | #include <QVector> | 22 | #include <QVector> | ||
21 | 23 | | |||
Show All 13 Lines | 36 | for (GeoDataPlacemark* placemark: document->placemarkList()) { | |||
35 | GeoDataGeometry const * const geometry = placemark->geometry(); | 37 | GeoDataGeometry const * const geometry = placemark->geometry(); | ||
36 | auto const visualCategory = placemark->visualCategory(); | 38 | auto const visualCategory = placemark->visualCategory(); | ||
37 | if (const auto prevLine = geodata_cast<GeoDataLineString>(geometry)) { | 39 | if (const auto prevLine = geodata_cast<GeoDataLineString>(geometry)) { | ||
38 | GeoDataLineString* reducedLine = new GeoDataLineString; | 40 | GeoDataLineString* reducedLine = new GeoDataLineString; | ||
39 | reduce(*prevLine, placemark->osmData(), visualCategory, reducedLine); | 41 | reduce(*prevLine, placemark->osmData(), visualCategory, reducedLine); | ||
40 | placemark->setGeometry(reducedLine); | 42 | placemark->setGeometry(reducedLine); | ||
41 | } else if (m_zoomLevel < 17) { | 43 | } else if (m_zoomLevel < 17) { | ||
42 | if (const auto prevRing = geodata_cast<GeoDataLinearRing>(geometry)) { | 44 | if (const auto prevRing = geodata_cast<GeoDataLinearRing>(geometry)) { | ||
43 | GeoDataLinearRing* reducedRing = new GeoDataLinearRing; | 45 | placemark->setGeometry(reducedRing(*prevRing, placemark, visualCategory)); | ||
44 | reduce(*prevRing, placemark->osmData(), visualCategory, reducedRing); | | |||
45 | placemark->setGeometry(reducedRing); | | |||
46 | } else if (const auto prevPolygon = geodata_cast<GeoDataPolygon>(geometry)) { | 46 | } else if (const auto prevPolygon = geodata_cast<GeoDataPolygon>(geometry)) { | ||
47 | GeoDataPolygon* reducedPolygon = new GeoDataPolygon; | 47 | placemark->setGeometry(reducedPolygon(*prevPolygon, placemark, visualCategory)); | ||
48 | GeoDataLinearRing const * prevRing = &(prevPolygon->outerBoundary()); | 48 | } else if (const auto building = geodata_cast<GeoDataBuilding>(geometry)) { | ||
49 | GeoDataLinearRing reducedRing; | 49 | if (const auto prevRing = geodata_cast<GeoDataLinearRing>(&building->multiGeometry()->at(0))) { | ||
50 | reduce(*prevRing, placemark->osmData().memberReference(-1), visualCategory, &reducedRing); | 50 | GeoDataLinearRing* ring = reducedRing(*prevRing, placemark, visualCategory); | ||
51 | reducedPolygon->setOuterBoundary(reducedRing); | 51 | GeoDataBuilding* newBuilding = new GeoDataBuilding(*building); | ||
52 | QVector<GeoDataLinearRing> const & innerBoundaries = prevPolygon->innerBoundaries(); | 52 | newBuilding->multiGeometry()->clear(); | ||
53 | for(int i = 0; i < innerBoundaries.size(); i++) { | 53 | newBuilding->multiGeometry()->append(ring); | ||
54 | prevRing = &innerBoundaries[i]; | 54 | placemark->setGeometry(newBuilding); | ||
55 | GeoDataLinearRing reducedInnerRing; | 55 | } else if (const auto prevPolygon = geodata_cast<GeoDataPolygon>(&building->multiGeometry()->at(0))) { | ||
56 | reduce(*prevRing, placemark->osmData().memberReference(i), visualCategory, &reducedInnerRing); | 56 | GeoDataPolygon* poly = reducedPolygon(*prevPolygon, placemark, visualCategory); | ||
57 | reducedPolygon->appendInnerBoundary(reducedInnerRing); | 57 | GeoDataBuilding* newBuilding = new GeoDataBuilding(*building); | ||
58 | newBuilding->multiGeometry()->clear(); | ||||
59 | newBuilding->multiGeometry()->append(poly); | ||||
60 | placemark->setGeometry(newBuilding); | ||||
58 | } | 61 | } | ||
59 | placemark->setGeometry(reducedPolygon); | | |||
60 | } | 62 | } | ||
61 | } | 63 | } | ||
62 | } | 64 | } | ||
63 | } | 65 | } | ||
64 | 66 | | |||
65 | qint64 NodeReducer::remainingNodes() const | 67 | qint64 NodeReducer::remainingNodes() const | ||
66 | { | 68 | { | ||
67 | return m_remainingNodes; | 69 | return m_remainingNodes; | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | 129 | { | |||
182 | for (auto const &segment: segments) { | 184 | for (auto const &segment: segments) { | ||
183 | int diff = segment.second - segment.first; | 185 | int diff = segment.second - segment.first; | ||
184 | diff = diff > 0 ? diff : length + diff; | 186 | diff = diff > 0 ? diff : length + diff; | ||
185 | value = value % QStringLiteral(";") % QString::number(segment.first) % QStringLiteral("+") % QString::number(diff); | 187 | value = value % QStringLiteral(";") % QString::number(segment.first) % QStringLiteral("+") % QString::number(diff); | ||
186 | } | 188 | } | ||
187 | osmData.addTag(QStringLiteral("mx:bp"), value.mid(1)); | 189 | osmData.addTag(QStringLiteral("mx:bp"), value.mid(1)); | ||
188 | } | 190 | } | ||
189 | 191 | | |||
192 | GeoDataLinearRing *NodeReducer::reducedRing(const GeoDataLinearRing& prevRing, | ||||
193 | GeoDataPlacemark* placemark, | ||||
194 | const GeoDataPlacemark::GeoDataVisualCategory& visualCategory) | ||||
195 | { | ||||
196 | GeoDataLinearRing* reducedRing = new GeoDataLinearRing; | ||||
197 | reduce(prevRing, placemark->osmData(), visualCategory, reducedRing); | ||||
198 | return reducedRing; | ||||
199 | } | ||||
200 | | ||||
201 | GeoDataPolygon *NodeReducer::reducedPolygon(const GeoDataPolygon& prevPolygon, | ||||
202 | GeoDataPlacemark* placemark, | ||||
203 | const GeoDataPlacemark::GeoDataVisualCategory& visualCategory) | ||||
204 | { | ||||
205 | GeoDataPolygon* reducedPolygon = new GeoDataPolygon; | ||||
206 | GeoDataLinearRing const * prevRing = &(prevPolygon.outerBoundary()); | ||||
207 | GeoDataLinearRing reducedRing; | ||||
208 | reduce(*prevRing, placemark->osmData().memberReference(-1), visualCategory, &reducedRing); | ||||
209 | reducedPolygon->setOuterBoundary(reducedRing); | ||||
210 | QVector<GeoDataLinearRing> const & innerBoundaries = prevPolygon.innerBoundaries(); | ||||
211 | for(int i = 0; i < innerBoundaries.size(); i++) { | ||||
212 | prevRing = &innerBoundaries[i]; | ||||
213 | GeoDataLinearRing reducedInnerRing; | ||||
214 | reduce(*prevRing, placemark->osmData().memberReference(i), visualCategory, &reducedInnerRing); | ||||
215 | reducedPolygon->appendInnerBoundary(reducedInnerRing); | ||||
216 | } | ||||
217 | return reducedPolygon; | ||||
218 | } | ||||
219 | | ||||
190 | } | 220 | } |