Commit b1ee2d8c authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Simplify memory management

parent 453200a8
......@@ -16,6 +16,7 @@
#include "GeoDataCoordinates.h"
#include "MarbleMath.h"
#include "NodeReducer.h"
#include "OsmPlacemarkData.h"
#include <QDebug>
#include <QVector>
......@@ -32,29 +33,31 @@ NodeReducer::NodeReducer(GeoDataDocument* document, int zoomLevel) :
if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType) {
GeoDataLineString* prevLine = static_cast<GeoDataLineString*>(placemark->geometry());
GeoDataLineString* reducedLine = reduce(prevLine);
GeoDataLineString* reducedLine = new GeoDataLineString;
reduce(prevLine, reducedLine);
placemark->setGeometry(reducedLine);
}
else if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
GeoDataLinearRing* prevRing = static_cast<GeoDataLinearRing*>(placemark->geometry());
GeoDataLinearRing* reducedRing = reduce(prevRing);
GeoDataLinearRing* reducedRing = new GeoDataLinearRing;
reduce(prevRing, reducedRing);
placemark->setGeometry(reducedRing);
}
else if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType) {
GeoDataPolygon* reducedPolygon = new GeoDataPolygon;
GeoDataPolygon* prevPolygon = static_cast<GeoDataPolygon*>(placemark->geometry());
GeoDataLinearRing* prevRing = &(prevPolygon->outerBoundary());
GeoDataLinearRing* reducedRing = reduce(prevRing);
reducedPolygon->setOuterBoundary(*reducedRing);
delete reducedRing;
QVector<GeoDataLinearRing>& innerBoundaries = prevPolygon->innerBoundaries();
GeoDataLinearRing const * prevRing = &(prevPolygon->outerBoundary());
GeoDataLinearRing reducedRing;
reduce(prevRing, &reducedRing);
reducedPolygon->setOuterBoundary(reducedRing);
QVector<GeoDataLinearRing> const & innerBoundaries = prevPolygon->innerBoundaries();
for(int i = 0; i < innerBoundaries.size(); i++) {
prevRing = &innerBoundaries[i];
GeoDataLinearRing* reducedInnerRing = reduce(prevRing);
reducedPolygon->appendInnerBoundary(*reducedInnerRing);
delete reducedInnerRing;
GeoDataLinearRing reducedInnerRing;
reduce(prevRing, &reducedInnerRing);
reducedPolygon->appendInnerBoundary(reducedInnerRing);
}
placemark->setGeometry(reducedPolygon);
}
......
......@@ -25,14 +25,14 @@ public:
private:
template<class T>
T* reduce(T* lineString)
void reduce(T const * lineString, T* reducedLine)
{
qint64 const prevSize = lineString->size();
if (prevSize < 2) {
return new T(*lineString);
m_remainingNodes += prevSize;
return;
}
T* reducedLine = new T;
auto iter = lineString->begin();
GeoDataCoordinates currentCoords = *iter;
reducedLine->append(*iter);
......@@ -48,7 +48,6 @@ private:
qint64 reducedSize = reducedLine->size();
m_removedNodes += (prevSize - reducedSize);
m_remainingNodes += reducedSize;
return reducedLine;
//qDebug()<<"Nodes reduced "<<(prevSize - reducedSize)<<endl;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment