Skip to content
Permalink
Browse files

Avoid some unnecessary geometry clones during map to pixel

simplification
  • Loading branch information
nyalldawson committed May 21, 2018
1 parent c1661de commit 959d1e930b439e9e06abb5a9ebd34f89019e5f0f
Showing with 19 additions and 17 deletions.
  1. +18 −16 src/core/qgsmaptopixelgeometrysimplifier.cpp
  2. +1 −1 src/core/qgsmaptopixelgeometrysimplifier.h
@@ -68,7 +68,7 @@ bool QgsMapToPixelSimplifier::equalSnapToGrid( double x1, double y1, double x2,
//////////////////////////////////////////////////////////////////////////////////////////////

//! Generalize the WKB-geometry using the BBOX of the original geometry
static QgsGeometry generalizeWkbGeometryByBoundingBox(
static std::unique_ptr< QgsAbstractGeometry > generalizeWkbGeometryByBoundingBox(
QgsWkbTypes::Type wkbType,
const QgsAbstractGeometry &geometry,
const QgsRectangle &envelope,
@@ -81,7 +81,7 @@ static QgsGeometry generalizeWkbGeometryByBoundingBox(

if ( geometry.nCoordinates() <= minimumSize )
{
return QgsGeometry( geometry.clone() );
return std::unique_ptr< QgsAbstractGeometry >( geometry.clone() );
}

const double x1 = envelope.xMinimum();
@@ -92,7 +92,7 @@ static QgsGeometry generalizeWkbGeometryByBoundingBox(
// Write the generalized geometry
if ( geometryType == QgsWkbTypes::LineString && !isRing )
{
return QgsGeometry( qgis::make_unique< QgsLineString >( QVector<double>() << x1 << x2, QVector<double>() << y1 << y2 ) );
return qgis::make_unique< QgsLineString >( QVector<double>() << x1 << x2, QVector<double>() << y1 << y2 );
}
else
{
@@ -108,17 +108,17 @@ static QgsGeometry generalizeWkbGeometryByBoundingBox(
<< y2
<< y1 );
if ( geometryType == QgsWkbTypes::LineString )
return QgsGeometry( std::move( ext ) );
return ext;
else
{
std::unique_ptr< QgsPolygon > polygon = qgis::make_unique< QgsPolygon >();
polygon->setExteriorRing( ext.release() );
return QgsGeometry( std::move( polygon ) );
return polygon;
}
}
}

QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry( int simplifyFlags,
std::unique_ptr< QgsAbstractGeometry > QgsMapToPixelSimplifier::simplifyGeometry( int simplifyFlags,
SimplifyAlgorithm simplifyAlgorithm,
const QgsAbstractGeometry &geometry, double map2pixelTol,
bool isaLinearRing )
@@ -292,7 +292,7 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry( int simplifyFlags,
// Bad luck! The simplified geometry is invalid and approximation by bounding box
// would create artifacts due to long segments.
// We will return the original geometry
return QgsGeometry( geometry.clone() );
return std::unique_ptr< QgsAbstractGeometry >( geometry.clone() );
}
}

@@ -305,20 +305,21 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry( int simplifyFlags,
}
}

return QgsGeometry( output.release() );
return output;
}
else if ( flatType == QgsWkbTypes::Polygon )
{
const QgsPolygon &srcPolygon = dynamic_cast<const QgsPolygon &>( geometry );
std::unique_ptr<QgsPolygon> polygon( new QgsPolygon() );
polygon->setExteriorRing( qgsgeometry_cast<QgsCurve *>( simplifyGeometry( simplifyFlags, simplifyAlgorithm, *srcPolygon.exteriorRing(), map2pixelTol, true ).constGet()->clone() ) );
std::unique_ptr<QgsAbstractGeometry> extRing = simplifyGeometry( simplifyFlags, simplifyAlgorithm, *srcPolygon.exteriorRing(), map2pixelTol, true );
polygon->setExteriorRing( qgsgeometry_cast<QgsCurve *>( extRing.release() ) );
for ( int i = 0; i < srcPolygon.numInteriorRings(); ++i )
{
const QgsCurve *sub = srcPolygon.interiorRing( i );
std::unique_ptr< QgsCurve > ring( qgsgeometry_cast<QgsCurve *>( simplifyGeometry( simplifyFlags, simplifyAlgorithm, *sub, map2pixelTol, true ).constGet()->clone() ) );
polygon->addInteriorRing( ring.release() );
std::unique_ptr< QgsAbstractGeometry > ring = simplifyGeometry( simplifyFlags, simplifyAlgorithm, *sub, map2pixelTol, true );
polygon->addInteriorRing( qgsgeometry_cast<QgsCurve *>( ring.release() ) );
}
return QgsGeometry( polygon.release() );
return polygon;
}
else if ( QgsWkbTypes::isMultiType( flatType ) )
{
@@ -328,11 +329,12 @@ QgsGeometry QgsMapToPixelSimplifier::simplifyGeometry( int simplifyFlags,
for ( int i = 0; i < numGeoms; ++i )
{
const QgsAbstractGeometry *sub = srcCollection.geometryN( i );
collection->addGeometry( simplifyGeometry( simplifyFlags, simplifyAlgorithm, *sub, map2pixelTol, false ).constGet()->clone() );
std::unique_ptr< QgsAbstractGeometry > part = simplifyGeometry( simplifyFlags, simplifyAlgorithm, *sub, map2pixelTol, false );
collection->addGeometry( part.release() );
}
return QgsGeometry( collection.release() );
return collection;
}
return QgsGeometry( geometry.clone() );
return std::unique_ptr< QgsAbstractGeometry >( geometry.clone() );
}

//////////////////////////////////////////////////////////////////////////////////////////////
@@ -378,5 +380,5 @@ QgsGeometry QgsMapToPixelSimplifier::simplify( const QgsGeometry &geometry ) con
return geometry;
}

return simplifyGeometry( mSimplifyFlags, mSimplifyAlgorithm, *geometry.constGet(), mTolerance, false );
return QgsGeometry( simplifyGeometry( mSimplifyFlags, mSimplifyAlgorithm, *geometry.constGet(), mTolerance, false ) );
}
@@ -58,7 +58,7 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier

private:
//! Simplify the geometry using the specified tolerance
static QgsGeometry simplifyGeometry( int simplifyFlags, SimplifyAlgorithm simplifyAlgorithm, const QgsAbstractGeometry &geometry, double map2pixelTol, bool isaLinearRing );
static std::unique_ptr<QgsAbstractGeometry> simplifyGeometry( int simplifyFlags, SimplifyAlgorithm simplifyAlgorithm, const QgsAbstractGeometry &geometry, double map2pixelTol, bool isaLinearRing );

protected:
//! Current simplification flags

1 comment on commit 959d1e9

@slarosa

This comment has been minimized.

Copy link
Member

@slarosa slarosa commented on 959d1e9 May 22, 2018

hi @nyalldawson, building now on mac I am getting the following:

[  0%] Building CXX object src/core/CMakeFiles/qgis_core.dir/qgsmaptopixelgeometrysimplifier.cpp.o
/Users/slarosa/dev/qgis-src/QGIS/src/core/qgsmaptopixelgeometrysimplifier.cpp:111:14: error: no viable conversion from returned value of type 'unique_ptr<QgsLineString>' to function return type 'unique_ptr<QgsAbstractGeometry>'
      return ext;
             ^~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2553:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::unique_ptr<QgsLineString>' to 'const std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY unique_ptr
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2582:49: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsLineString>' to 'nullptr_t' for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2609:31: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsLineString>' to 'std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &&' for 1st argument
    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
                              ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2613:9: note: candidate constructor [with _Up = QgsLineString, _Ep = std::__1::default_delete<QgsLineString>] not viable: no known conversion from 'std::unique_ptr<QgsLineString>' to 'unique_ptr<QgsLineString, std::__1::default_delete<QgsLineString> > &&' for 1st argument
        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2628:35: note: candidate template ignored: could not match 'auto_ptr' against 'unique_ptr'
        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
                                  ^
/Users/slarosa/dev/qgis-src/QGIS/src/core/qgsmaptopixelgeometrysimplifier.cpp:116:14: error: no viable conversion from returned value of type 'unique_ptr<QgsPolygon>' to function return type 'unique_ptr<QgsAbstractGeometry>'
      return polygon;
             ^~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2553:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::unique_ptr<QgsPolygon>' to 'const std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY unique_ptr
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2582:49: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsPolygon>' to 'nullptr_t' for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2609:31: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsPolygon>' to 'std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &&' for 1st argument
    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
                              ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2613:9: note: candidate constructor [with _Up = QgsPolygon, _Ep = std::__1::default_delete<QgsPolygon>] not viable: no known conversion from 'std::unique_ptr<QgsPolygon>' to 'unique_ptr<QgsPolygon, std::__1::default_delete<QgsPolygon> > &&' for 1st argument
        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2628:35: note: candidate template ignored: could not match 'auto_ptr' against 'unique_ptr'
        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
                                  ^
/Users/slarosa/dev/qgis-src/QGIS/src/core/qgsmaptopixelgeometrysimplifier.cpp:308:12: error: no viable conversion from returned value of type 'unique_ptr<QgsCurve>' to function return type 'unique_ptr<QgsAbstractGeometry>'
    return output;
           ^~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2553:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::unique_ptr<QgsCurve>' to 'const std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY unique_ptr
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2582:49: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsCurve>' to 'nullptr_t' for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2609:31: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsCurve>' to 'std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &&' for 1st argument
    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
                              ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2613:9: note: candidate constructor [with _Up = QgsCurve, _Ep = std::__1::default_delete<QgsCurve>] not viable: no known conversion from 'std::unique_ptr<QgsCurve>' to 'unique_ptr<QgsCurve, std::__1::default_delete<QgsCurve> > &&' for 1st argument
        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2628:35: note: candidate template ignored: could not match 'auto_ptr' against 'unique_ptr'
        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
                                  ^
/Users/slarosa/dev/qgis-src/QGIS/src/core/qgsmaptopixelgeometrysimplifier.cpp:322:12: error: no viable conversion from returned value of type 'unique_ptr<QgsPolygon>' to function return type 'unique_ptr<QgsAbstractGeometry>'
    return polygon;
           ^~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2553:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::unique_ptr<QgsPolygon>' to 'const std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY unique_ptr
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2582:49: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsPolygon>' to 'nullptr_t' for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2609:31: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsPolygon>' to 'std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &&' for 1st argument
    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
                              ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2613:9: note: candidate constructor [with _Up = QgsPolygon, _Ep = std::__1::default_delete<QgsPolygon>] not viable: no known conversion from 'std::unique_ptr<QgsPolygon>' to 'unique_ptr<QgsPolygon, std::__1::default_delete<QgsPolygon> > &&' for 1st argument
        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2628:35: note: candidate template ignored: could not match 'auto_ptr' against 'unique_ptr'
        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
                                  ^
/Users/slarosa/dev/qgis-src/QGIS/src/core/qgsmaptopixelgeometrysimplifier.cpp:335:12: error: no viable conversion from returned value of type 'unique_ptr<QgsGeometryCollection>' to function return type 'unique_ptr<QgsAbstractGeometry>'
    return collection;
           ^~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2553:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::unique_ptr<QgsGeometryCollection>' to 'const std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY unique_ptr
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2582:49: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsGeometryCollection>' to 'nullptr_t' for 1st argument
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2609:31: note: candidate constructor not viable: no known conversion from 'std::unique_ptr<QgsGeometryCollection>' to 'std::__1::unique_ptr<QgsAbstractGeometry, std::__1::default_delete<QgsAbstractGeometry> > &&' for 1st argument
    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
                              ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2613:9: note: candidate constructor [with _Up = QgsGeometryCollection, _Ep = std::__1::default_delete<QgsGeometryCollection>] not viable: no known conversion from 'std::unique_ptr<QgsGeometryCollection>' to 'unique_ptr<QgsGeometryCollection, std::__1::default_delete<QgsGeometryCollection> > &&' for 1st argument
        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2628:35: note: candidate template ignored: could not match 'auto_ptr' against 'unique_ptr'
        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
                                  ^
5 errors generated.
make[2]: *** [src/core/CMakeFiles/qgis_core.dir/qgsmaptopixelgeometrysimplifier.cpp.o] Error 1
make[1]: *** [src/core/CMakeFiles/qgis_core.dir/all] Error 2
make: *** [all] Error 2

Is the error related to those changes?

Please sign in to comment.
You can’t perform that action at this time.